# Question about JLD2 save/load of RData nested list

**URL:** <https://discourse.julialang.org/t/question-about-jld2-save-load-of-rdata-nested-list/25649>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 25, 2019, 12:17pm UTC](https://discourse.julialang.org/t/question-about-jld2-save-load-of-rdata-nested-list/25649 "2019-06-25T12:17:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [June 25, 2019, 12:17pm UTC](https://discourse.julialang.org/t/question-about-jld2-save-load-of-rdata-nested-list/25649/1 "2019-06-25T12:17:21Z")

</div>

suppose i have this

```julia
module jldtest

	using DataFrames
	using JLD2, FileIO
	using RData
	using RCall

	# make some R data 
	R"""
	rdata <- list(a = runif(3), b = letters[1:3])
	save(rdata, file = 'rr.RData')
	"""

	d = DataFrame(a = 1:3,b = rand(3))
	save(df) = FileIO.save("test.jld2",Dict("data" => df))

	function dosave()
		d = Dict()
		d[:jl] = DataFrame(a = 1:3,b = rand(3))
		d[:r] = FileIO.load("rr.RData")
		FileIO.save("test.jld2", Dict("data" => d))
	end

	doload() = FileIO.load("test.jld2")["data"]

	function dowork()
		d = doload()
		# work
		return nothing
	end

end

```

now let’s run this

```julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.1.0 (2019-01-21)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> include("jld2.jl")
Main.jldtest

julia> jldtest.dosave()

julia> jldtest.doload()
┌ Warning: type DataFrames.DataFrame does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/KjBIK/src/data.jl:1153
┌ Warning: type DataFrames.Index does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/KjBIK/src/data.jl:1153
┌ Warning: type RData.DictoVec{Array{Any,1}} does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/KjBIK/src/data.jl:1153
Dict{Any,Any} with 2 entries:
  :jl => ##DataFrames.DataFrame#364(AbstractArray{T,1} where T[[1, 2, 3], [0.54321, 0.673996, 0.666545]], ##DataFrames.Index#363(Dict(:a=>1,:b=>2), Symbol[:a…
  :r => Dict{String,Any}("rdata"=>##RData.DictoVec{Array{Any,1}}#365(Any[[0.895732, 0.391799, 0.953225], ["a", "b", "c"]], Dict("b"=>2,"a"=>1), Dict(2=>"b",…

```

- I think i understand the warning: because in the global module there is no `DataFrames` module loaded, julia has to reconstruct the type.
- however, why is that the case even if i don’t return the data at all into the global workspace?

```julia
julia> jldtest.dowork()
┌ Warning: type DataFrames.DataFrame does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/KjBIK/src/data.jl:1153
┌ Warning: type DataFrames.Index does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/KjBIK/src/data.jl:1153
┌ Warning: type RData.DictoVec{Array{Any,1}} does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/KjBIK/src/data.jl:1153

```

- Even though i say `using DataFrames` within my module, I get a warning that the datatype `DataFrame` needs to be reconstructed.
- I have an application that loads an R nested list as an `RData.DictoVec{Array{Any,1}}` into a module where I said `using RData`. the app crashes because it cannot reconstruct (as it can with the dataframe). I’m unsure why it crashes (above example doesn’t crash)
- I **have to** do `using RData`, _then_ load my module, then execute the function that loads the data. My script thus looks like

```julia
using RData
using MyModule
MyModule.run()

```

- I want to get rid of `using RData` on the first line. any solution?

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [June 25, 2019, 1:00pm UTC](https://discourse.julialang.org/t/question-about-jld2-save-load-of-rdata-nested-list/25649/2 "2019-06-25T13:00:31Z")

</div>

but aren’t you loading `RData` into the current module (probably `Main` here), rather than `MyModule`?

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [June 25, 2019, 1:03pm UTC](https://discourse.julialang.org/t/question-about-jld2-save-load-of-rdata-nested-list/25649/3 "2019-06-25T13:03:46Z")

</div>

That’s my current solution yes but I don’t like it. The last snippet fails without saying `using RData` in Main

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [June 25, 2019, 1:14pm UTC](https://discourse.julialang.org/t/question-about-jld2-save-load-of-rdata-nested-list/25649/4 "2019-06-25T13:14:20Z")

</div>

I meant “JLD2-loading” into `Main`.  
Without `using RData` also in `Main`, is there enough info?

Oh I see, your question is why can it reconstruct `DataFrames` but not `RData`?
