Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install R packages from the command line

Tags:

r

I need to build a reproducible R installation from the command line. Seems easy enough, so I created a file with my package names of interest, for example

packages.txt:

ggvis
glmnet
caret

The an R script called installPkgs.R:

f = read.csv('packages.txt', header=FALSE)
z = install.packages(f[,1], repos='https://cran.rstudio.com')   

And then I should be able to run this from the command line:

Rscript installPkgs.R

When I do, the packages are downloaded but not installed. What am I missing?

like image 980
KirkD-CO Avatar asked Mar 28 '19 19:03

KirkD-CO


People also ask

How do I manually install an R package?

Go into R, click on Packages (at the top of the R console), then click on "Install package(s) from local zip files", then find the zip file with arm from wherever you just saved it. Do the same thing to install each of the other packages you want to install.

Which command in R is used to install R packages?

To install any package from CRAN, you use install. packages() . You only need to install packages the first time you use R (or after updating to a new version). **R Tip:** You can just type this into the command line of R to install each package.


1 Answers

Answering my own question so that the answer is obvious and not buried into the coimments.

In my code, the list of packages is being interpreted as a factor rather than character strings. So, I need to set the parameter in read.csv() or the global parameter stringsAsFactors = FALSE.

Urgh.

like image 74
KirkD-CO Avatar answered Sep 30 '22 20:09

KirkD-CO