Why are objects masked after running library(renv) in R?

93 views Asked by At

I'm following this steps, like in this workflow here:

  1. renv::init()
  2. working as usual and installing new packages
  3. renv::snapshot()

The problem I'm facing is while running library(renv), many functions are been masked, like load, so I have to re-mask them all over my code in order to make it work again. Like base::load(...) Is there a way to avoid this masking?

Here the logs while running library(renv):

> 
> Attaching package: ‘renv’
> 
> The following object is masked from ‘package:stats’:
> 
>     update
> 
> The following objects are masked from ‘package:utils’:
> 
>     history, upgrade
> 
> The following objects are masked from ‘package:base’:
> 
>     load, remove
2

There are 2 answers

0
Kevin Ushey On

renv is designed with the expectation that users will normally always use the renv:: prefix when referring to its functions; e.g.

renv::install()

For that reason, you normally shouldn't load renv via library(), and instead should use it via that prefix (unless you want to manage conflicts on the search path).

If you still want to load renv as a regular R package, I would recommend using:

library(renv, include.only = <...>)

to ensure only the functions you want on the search path are placed there.

0
polkas On

As I understand the exclude argument might solve your problem. like:

library(renv, exclude = c("load", "update"))

More secure will be to use methods directly for such conflicts by ::.