-
-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safe figure saving by default, + new arg #4965
base: v2
Are you sure you want to change the base?
Conversation
julia> p = plot(rand(10), safe_saving=true);
julia> savefig(p, "this.png")
"/Users/z/Projects/Plots.jl/this.png"
julia> savefig(p, "this.png")
┌ Warning: Filename /Users/z/Projects/Plots.jl/this.png already exists, defaulting to prevent overriding. To disable this behavior, provide `:safe_saving=false` kwarg, i.e. `plot(rand(10), safe_saving=false)`
└ @ PlotsBase ~/Projects/Plots.jl/PlotsBase/src/output.jl:142
julia> p = plot(rand(10), safe_saving=false);
julia> savefig(p, "this.png")
"/Users/z/Projects/Plots.jl/this.png" |
I'll fix the tests, once we agree if it goes into 2.0 or not. I was also thinking instead of making this a property of a plot, maybe just make it a flag in |
I would be in favor of making it a part of |
I can't understand how scopedvalues can help here. Can you give an example please? |
julia> using ScopedValues
julia> const DEFAULT_OVERWRITE = ScopedValue(false)
ScopedValue{Bool}(0)
julia> savefig(;overwrite = DEFAULT_OVERWRITE) = @show overwrite[]
savefig (generic function with 1 method)
julia> savefig()
overwrite[] = false
false
julia> with(DEFAULT_OVERWRITE => true) do
savefig()
end
overwrite[] = true
true |
I see, I meant about script usage. Probably some people have their research pipelines such that there is some saving done inside. Like having users modify so much code to accomodate such a change might be too drastic I was thinking that a user would set the flag in Prefernces.jl or startup.jl Now that I'm looking into these, where are the docs about setting the defaults? I can't seem to find the docs about default setting anymore |
I think its the tip on the bottom of this page: https://docs.juliaplots.org/stable/install/ |
So you still think ScopedValue is the right solution here? |
I do. I mean, you can still do something like const DEFAULT_OVERWRITE = ScopedValue(get(PLOTS_DEFAULTS, :overwrite, false)) To get change it based on some value in |
Like I suggested before in #3001