Error building and loading package when using renv

I'm trying to develop a new package. I follow the Rstudio dialog options (File -> New Project -> New Directory -> R Package) to create a new package. When I leave the option "use renv with this project" unchecked, I can build the default template project fine and it loads correctly. However, when I check the option to "use renv with this project", I get the following error when I try to build the default template project:

> library(mypackage)
Error in library(mypackage) : there is no package called ‘mypackage’

I checked my system package directory, and the package appears to be there. So, I wonder if it's a challenge with renv getting to install it locally in the project folder. I'm new to package development, so I apologize if I'm missing something basic. Your help is greatly appreciated.

1 Like




When I run that command I receive the following error:

> renv::install("mypackage")
Error: package 'mypackage' is not available

However, when I specify the full path to the location of the package (in my default package location), it installs correctly:

> renv::install("C:/R/Packages/mypackage")
Installing mypackage [0.1.0] ...
	OK [copied local binary]

I wonder if this has to do with where renv is looking for packages. In my usual instances of R, my .libPaths() is::

> .libPaths()
[1] "C:/R/Packages"        "C:/R/R-4.0.2/library"

However, in this instance when using renv, my .libPaths() is::

> .libPaths()
[1] "D:/Documents/GitHub/mypackage/renv/library/R-4.0/x86_64-w64-mingw32" "C:/Users/myusername/AppData/Local/Temp/RtmpumbqYa/renv-system-library"

Any ideas for how to get renv to look where my R instances typically look for packages ("C:/R/Packages") to identify those available for installation (including this package that I'm developing)? Thanks!

This topic was automatically closed after 45 days. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.