The reason this particular form of @load now shows a warning is that it
can't be made to work properly in a function. If you can't know either the
file name or the variable names ahead of time, there are two things you
could do:
- Use the load function (e.g. x = load("data_run$(run).jld")) rather than
the macro. This returns a Dict of all variables in the file, so you'd
access them as x["a"] etc.
- Use @eval @load $("data_run$(run).jld")
Simon
On Tuesday, August 30, 2016 at 3:05:58 PM UTC-4, Ethan Anderes wrote:
>
> I often use @load as a way to conveniently load a bunch of variables
> obtained from a simulation run.
> For example, the simulation script might look like this
>
> using JLD
> run = 1 # <--- simulation parameter
> a,b,c = 1,2,3
> @save "data_run$(run).jld" a b c
>
> Then, to view these simulations later, I would use the load macro. In v0.4
> my REPL session would look something like this:
>
> julia> using JLD
>
> julia> run = 1 # <--- specify which simulation run to load
> 1
>
> julia> @load "data_run$(run).jld"
> 3-element Array{Symbol,1}:
> :a
> :b
> :c
>
> julia> a
> 1
>
> julia> b
> 2
>
> julia> c
> 3
>
> However, in v0.5.0-rc3+0 , I get the following warning.
>
> julia> using JLD
>
> julia> run = 1 # <--- specify which simulation run to load
> 1
>
> julia> @load "data_run$(run).jld"
> WARNING: @load-ing a file without specifying the variables to be loaded may
> produce
> unexpected behavior unless the file is specified as a string literal. Future
> versions of JLD will require that the file is specified as a string literal
> in this case.
> 3-element Array{Symbol,1}:
> :a
> :b
> :c
>
> julia> a
> 1
>
> julia> b
> 2
>
> julia> c
> 3
>
> julia> Pkg.status("JLD")
> - JLD 0.6.3+ master
>
> I was going to file an issue with JLD but I figured I would post here
> first to see if I’m using an ill-advised workflow or missing some simple
> work around.
>
> Note: there are a few features of my situation which makes @load
> particularly convenient.
>
> - Each simulation produces a bunch of variables and some older runs have a
> smaller subset of variables than newer ones. This makes it clumsy to use the
> load function (rather than the macro) where one needs to specify the variable
> names ahead of time.
> - I need to load in multiple `.jld` files, sometimes in a large plotting
> script, so printing out each file string in the REPL and pasting it into the
> REPL after `@load` is also unwieldy.
>
>
>