Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install binary zipped R package via command line

I am trying to install zipped binary R packages via command line on a windows 7 machine with

R CMD INSTALL packagename

but it doesn't work. I read that CMD INSTALL can't be used to install binary packages. So how can I install binary packages via command line?

like image 529
Kai Avatar asked Aug 16 '11 08:08

Kai


People also ask

How do I install R packages from a zip file?

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.

How do I install binary in R?

The universal binary of R is made available as an installer package; simply download the file and double-click the package to install the application. The legacy R installers are packaged on a disk image file (like most Mac OS X applications).

What is the command to install a package in R?

The most common way is to use the CRAN repository, then you just need the name of the package and use the command install. packages("package") .


3 Answers

An alternative for newbies like me that is hassle free would be:

 install.packages(file.choose(), repos=NULL)

The file.choose() command will show a window allowing you to choose the .zip file or the tar.gz file where you downloaded it. This command is very useful when you don't have enough rights on a Windows machine and run R from a flash drive like myself.

It is also useful before running this command to RENAME the zip file you are going to install into the package name that you intend to use.

like image 142
moldovean Avatar answered Oct 17 '22 11:10

moldovean


You can use the Rscript front end to run code as if it were in a running R session. Say the package you want to install is foo.zip in the current working directory. I'm probably abusing Rscript here, but it works for me:

Rscript -e "install.packages('foo.zip', repos = NULL)"

You need to supply the path to the binary package if it is not in the directory where there script is running. repos = NULL is the trick to get install.packages() to work from a local file. Read ?install.packages for more info on other arguments you might want to specify, especially lib. Note that you don't benefit from automatic dependency resolution when doing this - you need a repo for that and if you supply one, R will try to download packages.

You are right about R CMD INSTALL; the R Installation and Administration manual has the following in Section 6.3:

To install packages from source in a Unix-alike use

    R CMD INSTALL -l /path/to/library pkg1 pkg2 ...
like image 45
Gavin Simpson Avatar answered Oct 17 '22 12:10

Gavin Simpson


An addition to @moldovean's answer: I used to save the zipped file(copy from temp to a R download folder for future reference). When I updated R from 2.15.1 to 3.0.1, I run these commands for easy installation:

setwd("C:/Downloads/R Packages");
packages<-dir();
install.packages(x, repos=NULL) #where x is the name of package

And R installed all packages automatically from zipped files. Now I can update all of them with one command only(google it)

like image 6
Outlier Avatar answered Oct 17 '22 12:10

Outlier