Is there a way to install local packages in packrat without downloading from GitHub?

1.6k views Asked by At

I am using packrat in an R project, and it is rather laborious to add functions to my custom package, rebuild, push to GitHub, and then re-download the package from GitHub into packrat. Besides taking a lot of extra time this involves pushing my new functions to the master, which is not ideal when I'm still iterating on new functions.

If I were not using packrat I could just rebuild the package locally, restart R and the updated version of the package would be accessible.

Is there a way to speed up this workflow and still use packrat?

2

There are 2 answers

1
Joe On

Here is how I installed a locally built package in packrat:

After building the package locally from RStudio, a path was displayed in the Build tab:

* installing to library ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library’

Copy this path along with the package name and return to your project that is using packrat. In the console enter:

path_to_my_locally_built_package <- "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/my_package"

devtools::install(path_to_my_locally_built_package)

library(my_package)

Your local package will now be in packrat and all of its functions will be available for use.

0
eric_kernfeld On

Is there a reason not to do what the packrat folks recommend?

packrat::set_opts(local.repos = c("path/to/my/packages"))
packrat::install_local("mypackage")