35

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.

Berk U.
  • 6,728
  • 5
  • 43
  • 67
  • 1
    It's certainly possible to do this, and the `install.packages` function will accept a NULL repository argument. – IRTFM Feb 11 '13 at 06:04
  • 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)` – Berk U. Feb 11 '13 at 06:09
  • Not sure exactly that formalism would work, assuming it is really a list. The first argument needs to be a character vector. – IRTFM Feb 11 '13 at 06:13

4 Answers4

33

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

iTech
  • 17,764
  • 4
  • 54
  • 78
  • Thanks! Just to make sure: since I'm working on UNIX computers, shouldn't the packages be in tar.gz format? – Berk U. Feb 11 '13 at 06:10
  • 1
    If you have the package source `.tar.gz` it should work as well – iTech Feb 11 '13 at 06:13
  • 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 status` – arun Jul 20 '16 at 21:07
  • how do you download packages as zip files ? – user3079364 Oct 19 '18 at 20:01
1

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')
adramazany
  • 567
  • 7
  • 14
1

I also went through the same problem while installing caret package, There are many dependencies of 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)
Thunder
  • 9,775
  • 25
  • 79
  • 113
0
install.packages("libname",lib = "file://F:/test")
Dharman
  • 26,923
  • 21
  • 73
  • 125
Angel
  • 61
  • 1
  • 1
  • 12
  • 1
    I added it because myself had problems with the format of library. Thought maybe it helps someone else! – Angel Apr 21 '17 at 06:23