The way we do it in LightGraphs is as follows:
try
using GraphMatrices
import GraphMatrices.CombinatorialAdjacency
nothing
catch
end
and then
if isdefined(:GraphMatrices)
... conditional code here
end
taking advantage of the fact that :Package is defined when "Package" is
imported.
On Thursday, November 5, 2015 at 3:39:32 PM UTC-8, Ismael VC wrote:
>
> This also works:
>
> julia> function foo(x, y; make_plot::Bool=false)
> # ...
> if make_plot
> @eval using Gadfly
> plot(x = x, y = y, Geom.line)
> end
> # ...
> end
> foo (generic function with 1 method)
>
> julia> x = -π:0.1:π; foo(x, sin(x))
>
> julia> x = -π:0.1:π; foo(x, sin(x), make_plot = true)
>
> julia>
>
>
>
> El martes, 4 de agosto de 2015, 12:26:58 (UTC-5), Felipe Jiménez escribió:
>>
>> I've written a function, fwhm, that goes fast without plotting anything
>> (which is the usual usage).
>> But if one optional argument is dodraw = true, it draws a figure to
>> visualize its doings.
>> To draw the figure it uses the package Gadfly. But "using Gadfly" takes
>> time to execute (the first time), and most of the sessions it is not needed
>> because by default dodraw = false.
>> Since I cannot do "using Gadfly" inside a function, I cannot do something
>> like this:
>>
>> function fwhm(xk, yk; dodraw::Bool=false)
>> # ...
>>
>> if dodraw
>> using Gadfly
>> plot(x=xk, y=yk) # etc.
>> end
>>
>> # ...
>> end
>>
>> I don't want to add overhead time to every session I use the module where
>> fwhm is, because most of the times dodraw = false and I just need a fast
>> result without figures.
>> Any idea?
>> Thank you in advance.
>>
>