[JLD2] How to save an obj on file, replacing that object but not the whole file

The other idea is to delete! the prior “variable”.

julia> using JLD2

julia> A = rand(16); B = rand(16);

julia> jldsave("example.jld2"; A, B)

julia> jldopen("example.jld2", "a+") do f
           delete!(f, "A")
           f["A"] = zeros(16)
       end
16-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

julia> jldopen("example.jld2", "a+") do f
           f["A"]
       end
16-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
2 Likes