sharoz
sharoz

Reputation: 6345

Is it possible for `renv` to be "bypassed" or temporarily turned off?

I have an RStudio project that manages packages using renv, which works great.

But sometimes I want to debug or explore something using libraries on my main environment(right word?) that I don't want to add to the project. For example, maybe I want to run some long debug function and call beepr::beep() at the end. Is that possible without installing the beepr package to the project?

long_process()
beepr::beep() # How do I make this call?

Upvotes: 4

Views: 766

Answers (2)

Matifou
Matifou

Reputation: 8920

Answering the main title rather than the specific example used: to temporarily disable renv, use renv::deactivate(). This will mainly comment/deactivate the line source("renv/activate.R") in .Rprofile, which has the main effect of changing your library path.

Check:

proj <- "your-project-path"
## with renv
renv::activate(proj)
.libPaths()
#> [1] "your-project-path/renv/library/R-4.2/x86_64-pc-linux-gnu"
#> [2] "/usr/lib/R/library"
## without renv
renv::deactivate(proj)
.libPaths()
#> [1] "/home/usert/R/x86_64-pc-linux-gnu-library/4.2"
#> [2] "/usr/local/lib/R/site-library"                  
#> [3] "/usr/lib/R/site-library"                        
#> [4] "/usr/lib/R/library"

Created on 2022-09-10 by the reprex package (v2.0.1)

Upvotes: 2

caldwellst
caldwellst

Reputation: 5956

You could technically disable sandboxing, which is where renv prevents packages installed in the system library from being made available in the project (which is why you wouldn't be able to use beepr::beep() in your example. You can change your user configuration easily, just see the documentation from env. The setting here would be renv.config.sandbox.enabled.

However, I don't think that's the best option. Depending on the snapshot type settings described in ?renv::snapshot, you needn't worry about installing beepr but it getting added to the lock file.

You can check or set the snapshot type using:

renv::settings$snapshot.type()

If you install the beepr package in the environment, then depending on the type you will get:

  • "all": the only problematic setting. If you run snapshot with beepr actively loaded, it will be added to the lock file, which isn't what you want.

  • "implicit": as long as beepr isn't referenced in R code saved to the library, it won't be added to the lock file.

  • "explicit": only adds packages that are defined in DESCRIPTION.

  • "custom": as implied, is custom, but depends on files saved in the project, so would only add beepr if saved somewhere rather than just used interactively using debug.

So, in summary, unless you are using "all", you should be safe to install and use beepr! If you are using "all", then just be sure to detach("package:beepr", unload = TRUE) before running snapshot().

Upvotes: 5

Related Questions