0

I have a few libraries that I use in the script namely

tidyverse
readxl

How can I make it so that if someone run's my script it will either download them if they don't have it already or somehow package the libraries together in a zip?

Does packrat do this?

This is all I have but its inelegant for novice R users:

# uncomment these lines before you start to install the packages then 
# install.packages("dplyr")
# install.packages("readxl")

library(dplyr)
library(readxl)
ahtmatrix
  • 539
  • 1
  • 7
  • 19
  • 3
    This probably is what you need https://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them – Ronak Shah Mar 04 '20 at 08:06
  • It is probably rarely a good practice to install packages automatically. You may inadvertently overwrite someone's versions and virtual environments are not a thing yet in R (but see i.e. renv package). As an alternative, I would suggest adding a comprehensive instructions at the beginning of your script which packages to install and how in case you see errors X, Y and Z. I understand some might wish this to be a brainless process, but I think it's important for whomever is running the script to have at least rudimentary understanding of what is happening. – Roman Luštrik Mar 04 '20 at 08:31

0 Answers0