Manually Downloading and Installing Packages in R
Asked Answered
D

4

45

I am currently trying to run some R code on a computing cluster but cannot run the install.packages function due to some weird firewall settings on my cluster. Since I am only using a few packages in my R code, I was hoping to avoid using the install.packages function by downloading and installing the packages manually.

Note: I am aware that there is a way to avoid this issue by using an HTTP proxy as described in the R FAQ. Unfortunately the people in charge of my cluster are not being helpful in setting this up so I'm forced to consider this alternative approach.

Ideally, I would like to download the packages files from CRAN to my computer, then upload these files to the cluster and install them using the appropriate commands in R. In addition, I would also like to make sure that the packages are installed to a location of my choice since I do not have the permission to "write" in the default R directory (I believe that I can do this within R by using the .libPaths function)

Lastly, the computers that I am working with on the cluster are Unix x86_64.

Doubleminded answered 11/2, 2013 at 5:59 Comment(5)
It's certainly possible to do this, and the install.packages function will accept a NULL repository argument.Mcevoy
Awesome! I didn't realize this at all. Just to confirm the following snippet should work, correct? install.packages(pkgs = MyListofTARGZFiles, repos = NULL, lib = MyLibraryDirectory)Doubleminded
Not sure exactly that formalism would work, assuming it is really a list. The first argument needs to be a character vector.Mcevoy
I wonder where do you get the .tar.gz source packages in the first place?Ownership
Found it: cran.r-project.org/web/packages/available_packages_by_name.htmlOwnership
I
41

You can install the package manually using the following command

install.packages('package.zip', lib='destination_directory',repos = NULL)

See the help of ?install.packages, for further description

Indebtedness answered 11/2, 2013 at 6:9 Comment(4)
Thanks! Just to make sure: since I'm working on UNIX computers, shouldn't the packages be in tar.gz format?Doubleminded
If you have the package source .tar.gz it should work as wellIndebtedness
In my case, this throws an error telling a NAMESPACE file is required. > install.packages('/Users/arun/Desktop/DiagnosisMed_0.2.3.tar.gz', lib="~/Library/R/3.3/library/", repos = NULL) * installing *source* package ‘DiagnosisMed’ ... ERROR: a 'NAMESPACE' file is required * removing ‘/Users/arun/Library/R/3.3/library/DiagnosisMed’ Warning in install.packages : installation of package ‘/Users/arun/Desktop/DiagnosisMed_0.2.3.tar.gz’ had non-zero exit statusAlvinalvina
how do you download packages as zip files ?Perigee
P
3

I also went through the same problem while installing the caret package. There are many dependencies of the caret package. So, I did the following:

install.packages('caret'): This gives all packages in zip format the location of download is shown in the error message. Unzip all packages from download source to a location for example in C:/PublicData/RawRPackages, then run following command.

foldername <- 'C:/PublicData/RawRPackages'
install.packages(paste(foldername, 'caret', sep = '/'),
                 repos = NULL, type = "source")
library(caret, lib.loc = foldername)
Pyrrhuloxia answered 12/8, 2018 at 12:38 Comment(1)
Your solution is very useful, because it is not necessary to know the destination directory of the package! It is found automatically.Bergwall
H
2

this the better way, if we want to download and install locally :

download.packages('lib_name',destdir='dest_path')

for example :

download.packages('RJDBC',destdir='d:/rlibs')
Hoskinson answered 21/4, 2018 at 9:58 Comment(1)
Am I missing something, or does this not pull down dependencies?Thayer
B
0
install.packages("libname",lib = "file://F:/test")
Briticism answered 20/4, 2017 at 19:36 Comment(1)
I added it because myself had problems with the format of library. Thought maybe it helps someone else!Briticism

© 2022 - 2024 — McMap. All rights reserved.