Outside of posting your new R package to CRAN, how does one easily share a package with others? Even simply via email to coworkers or collaborators? Since we just talked about creating R packages, let’s learn how to share.
Projectsmenu in the top-right. This happens by either
Rprojfile in the package of interest
Buildtab and click
Build Source Package
You’ll then see something like this in the Console:
* checking for file 'RTesty/DESCRIPTION' ... OK * preparing 'RTesty': * checking DESCRIPTION meta‐information ... OK * checking for LF line‐endings in source and make files * checking for empty or unneeded directories * building 'RTesty_0.1.tar.gz'
R and devtools is kindly helping to verify that your package meets minimum requirements for proper distribution. A new file will appear whose name ends with .tar.gz
Send this compressed tarball to your destination machine via email, etc. Put it in R’s library directory.
On the destination machine open RStudio and use install.packages on the newly-placed tarball. Note that R folder paths use forward slashes. Mine looks like this:
install.packages("C:/Program Files/R/R‐3.2.2/library/RTesty_0.1.tar.gz", repos = NULL, type="source")
Note: this could also be done via
Install Packages -> under
Install from, select
Package Archive File
The library should load without errors and the output should match expectations. If you’re following along, you can start with a super simple example like this.
Note that it’s highly advisable to push your code to a remote repo like Github (even if it’s privately) so you’re precious work isn’t ever compromised by a hardware failure or stolen laptop.