Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install an R package directly from a URL for the package source

Tags:

r

I would like to install a package directly from a URL for the package source. I want to do this to make it easy for people to test a pre-release version of the package which should not be widely (or permanently) available. This is a similar question but it is different because it only describes how to install from local files not general URLs.

For the sake of this question I will use a link to the boot package source. Reading ?install.packages particularly the description of the pkgs argument suggests:

install.packages(   "http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz",    repos = NULL, type = "source" ) 

However this fails with:

Warning in install.packages :   installation of package    ‘http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz’    had non-zero exit status 

Suggesting that the URL is being interpreted as the package name, not its location. We can work around this with the following two step procedure:

download.file(   "http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz",    "boot" ) install.packages("boot", repos = NULL, type = "source") 

But I would prefer to do this with a single call to install.packages only; and since install.packages is capable of downloading files anyway I feel this should be possible.

like image 374
orizon Avatar asked May 07 '13 06:05

orizon


People also ask

How do I manually install a package in R?

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.

What is the correct way to install the packages in R?

Open R via your preferred method (icon on desktop, Start Menu, dock, etc.) Click “Packages” in the top menu then click “Install package(s)”. Choose a mirror that is closest to your geographical location. Now you get to choose which packages you want to install.


2 Answers

install.packages now works with http URLs (not https yet) as of 3.1.1. This works for me:

install.packages("http://www.lepem.ufc.br/jaa/colorout_1.1-0.tar.gz", repos=NULL) 

Edit: As of R 3.2.0, https is builtin via libcurl. This should work now:

install.packages("https://github.com/hadley/devtools/archive/v1.7.0.tar.gz",                  repos=NULL, method="libcurl") 

Edit: As of R 3.2.2, https should work with default options assuming libcurl support was compiled in.

Edit 2016-04-20: There may be some issues downloading packages hosted on S3, but method='wget' seems to work for those for now.

like image 96
Neal Fultz Avatar answered Sep 25 '22 10:09

Neal Fultz


See ?install_url in the devtools package.

like image 42
G. Grothendieck Avatar answered Sep 25 '22 10:09

G. Grothendieck