Earlier, you configured Packrat support in RStudio. If you use RStudio as your primary IDE, you'll now be benefitting from Packrat's dependency management. If you aren't using RStudio or aren't yet using Packrat, you're still using Packrat.
The IQSS Shiny toolchain installs Packrat during the build process and determines your dependencies automatically, without any intervention, but this makes the build process very long. Every time you build your application in Docker or Heroku, instead of using a stored, cached set of dependencies, the Shiny toolchain re-creates the packrat.lock file, requiring every dependency to be re-compiled and re-installed.
Installing Packrat into an R project outside of RStudio
All instructions below are summarized from .
Open your project's directory, and execute R.
cd heroku-docker-r-example-app
R
In the R console, run the following:
> install.packages("packrat")
trying URL 'http://cran.cnr.berkeley.edu/bin/macosx/el-capitan/contrib/3.6/packrat_0.5.0.tgz'
Content type 'application/x-gzip' length 456629 bytes (445 KB)
==================================================
downloaded 445 KB
The downloaded binary packages are in
/var/folders/nh/xkzmf2xj70q2v5_gjvf0kyz00000gn/T//Rtmp3svuh7/downloaded_packages
> packrat::init()
Initializing packrat project in directory:
- "~/projects/heroku-docker-r-example-app"
Adding these packages to packrat:
_
BH 1.69.0-1
R6 2.4.1
Rcpp 1.0.3
assertthat 0.2.1
backports 1.1.5
...
...
Initialization complete!
Packrat mode on. Using library in directory:
- "~/projects/heroku-docker-r-example-app/packrat/lib"
After your project's dependencies are installed, your project's dependencies will be saved to the file packrat/packrat.lock
Installing new packages to the Packrat bundle
During the course of application development, you may need to add new libraries. If you want to install a library and use it in your application, first, run R and install the library per usual, then create a new packrat snapshot. This will update packrat/packrat.lock with the new library.
If you've downloaded your project onto a completely new machine, you can restore all the required dependencies by open your project's directory, executing R and running:
The install.packages("packrat") is optional if Packrat is already installed.
Using .gitignore
You must have a proper .gitignore file within your project. Packrat downloads tarballs (compressed folders) of all your required libraries and places them in the packrat sub-directory of your project, check it out:
None of this should be committed or pushed to GitHub as our Shiny toolchain will look at packrat.lock and download, install, and clean up all your required libraries upon deploy.
Make sure you have a .gitignore in your repsitory that looks like this
Packrat creates an .Rprofile in your project directory, as well as packrat/packrat.lock and packrat/packrat.opts. All these files are essential to speeding up your deploys and managing dependencies.
First, commit and push the .gitignore above.
git add .gitignore; git commit -m 'Adding R .gitignore' .gitignore
Now, add and commit everything else.
git add -A; git commit -a -m 'Adding packrat support files'