rstudio / packrat

Packrat is a dependency management system for R
http://rstudio.github.io/packrat/
402 stars 90 forks source link

option setters clear other settings #655

Closed aronatkins closed 2 years ago

aronatkins commented 2 years ago

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:

https://github.com/rstudio/packrat/blob/c648ce2fb915289d3de5c58eae9b15202a839163/R/options.R#L173-L179

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

https://github.com/rstudio/packrat/blob/c648ce2fb915289d3de5c58eae9b15202a839163/R/options.R#L221-L223

aronatkins commented 2 years ago

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 commented 2 years ago

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"