How did renv know if a package is used? Happens in new package(in new project seems fine.)

59 Views Asked by At

I am using renv package 1.0.3 to manage my project library.

Using renv::status() method, we get something like:

 package      installed recorded used  
 nnet         y         y        n   

So that means I have nnet package installed by renv::install and recorded in renv.lock file. However, my hello.R file under the folder R in project test_project(path test_project/R/hello.R) contains these lines:

renv::install("nnet")
library(nnet)
which.is.max(c(1,2)) #the method defined in nnet

However, I kept on running renv::status() and renv::snapshot()

the line for nnet and col for used still shows 'n'

you can see the pic snap here:

enter image description here

The hello.R file snap is here:

enter image description here

How was the renv aware of which package is used and if it couldn't get the correct info how could we notify renv?

1

There are 1 best solutions below

0
cloudscomputes On

I think I find the answer myself, So I post it here.

Using renv, the behaviors in new package and new project are different.

you can use renv::settings$snapshot.type() to check it status.

If in 'implicit' mode, as by default in new project, once you save your change like library(tictoc), the renv will treat it as used.(but not its dependencies, those will get recorded as used once installed).

If in 'explicit' mode, as by default in new package, you can only record the package as used once it was added in the DESCRIPTION files using Imports or Depends.