Skip to content
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

option setters clear other settings #655

Closed
aronatkins opened this issue Feb 8, 2022 · 2 comments · Fixed by #656
Closed

option setters clear other settings #655

aronatkins opened this issue Feb 8, 2022 · 2 comments · Fixed by #656

Comments

@aronatkins
Copy link
Contributor

Using the option setter clears other configured options.

packrat::set_opts(ignored.packages = c("emo"), persist = FALSE)
packrat::opts$snapshot.recommended.packages(TRUE, persist = FALSE)
packrat::get_opts(c("ignored.packages"))
# => NULL

This is using the setter defined by:

packrat/R/options.R

Lines 173 to 179 in c648ce2

make_setter <- function(name) {
force(name)
function(x, persist = TRUE) {
if (missing(x)) return(get_opts(name))
else setOptions(setNames(list(x), name), persist = persist)
}
}

the setter is connected to the packrat::opts here:

packrat/R/options.R

Lines 221 to 223 in c648ce2

opts <- setNames(lapply(names(VALID_OPTIONS), function(x) {
make_setter(x)
}), names(VALID_OPTIONS))

@aronatkins
Copy link
Contributor Author

This is because the single-property setter is effectively a call to ::set_opts, which assumes all options are being set. The same effect can be seen below, but is expected, here.

packrat::set_opts(ignored.packages = c("emo"), persist = FALSE)
packrat::set_opts(snapshot.recommended.packages = TRUE, persist = FALSE)
packrat::get_opts(c("ignored.packages"))
# => NULL

@aronatkins
Copy link
Contributor Author

A workaround is to read all the packrat options, adjust the single target, then set all options together.

packrat::set_opts(ignored.packages = c("emo"), persist = FALSE)

o <- packrat::get_opts()
o[["snapshot.recommended.packages"]] <- TRUE
do.call(packrat::set_opts, o)

packrat::get_opts(c("ignored.packages", "snapshot.recommended.packages"))
# => [1] "emo"  "TRUE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant