41

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.
  • 7,018
  • 6
  • 44
  • 69
  • 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

36

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
  • 18,192
  • 4
  • 57
  • 80
  • 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
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')
adramazany
  • 625
  • 9
  • 15
2

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)
bathyscapher
  • 1,615
  • 1
  • 13
  • 18
Thunder
  • 10,366
  • 25
  • 84
  • 114
  • Your solution is very useful, because it is not necessary to know the destination directory of the package! It is found automatically. – EmaK Jan 28 '23 at 20:08
0
install.packages("libname",lib = "file://F:/test")
Dharman
  • 30,962
  • 25
  • 85
  • 135
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