29

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.

Community
  • 1
  • 1
orizon
  • 3,159
  • 3
  • 25
  • 30
  • The package is not being found in your original call because it is not there. It is `boot_1.3-9.tar.gz` in that directory. – Simon O'Hanlon May 07 '13 at 06:49
  • @SimonO101 sorry that was a mistake I made in writing the question. Fixing it does not change the behaviour unfortunately. – orizon May 07 '13 at 06:58
  • 1
    Why not set up the directory in which you store the source package as a repository? [Here is an example](http://stackoverflow.com/questions/2905650/creating-a-local-r-package-repository), though you'd likely want to substitute `type="source"` for `type="win.binary"` – Josh O'Brien May 07 '13 at 07:13
  • Good. Now that I understand what you're after, I'll make that an answer. – Josh O'Brien May 07 '13 at 07:19

4 Answers4

26

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.

Neal Fultz
  • 9,282
  • 1
  • 39
  • 60
  • This method failed with a '403 Forbidden' error when `install.packages()` tried to download the file using `download.file()`. Not sure if libcurl support was compiled in but `devtools::install_url()` suggested by @G. Grothendieck works with no problem. – Stefan Avey Apr 18 '17 at 15:50
  • That sounds like a authentication issue. What url are you trying to download? – Neal Fultz Apr 18 '17 at 15:54
  • Yes, it seems to be but for a different URL (maybe where the file is actually hosted). Compare `install.packages("https://bitbucket.org/kleinstein/logminer/downloads/pclogit_0.2.tar.gz")` to `devtools::install.packages("https://bitbucket.org/kleinstein/logminer/downloads/pclogit_0.2.tar.gz")` – Stefan Avey Apr 19 '17 at 21:27
  • That url redirects to `https://bbuseruploads.s3.amazonaws.com/786fe3b9-c855-4ead-8e92-9a923307571e/downloads/198445c2-b162-4e7b-9de9-2a5def8c1e70/pclogit_0.2.tar.gz?Signature=rkSXfOUzDeYaOiA0s%2BcFOqA33jc%3D&Expires=1492645028&AWSAccessKeyId=AKIAIVFPT2YJYYZY3H4A&versionId=E0GlRikyD2HwjjssxYfoSos.KUV9jOtd&response-content-disposition=attachment%3B%20filename%3D%22pclogit_0.2.tar.gz%22`. I think amazon is blocking base R's user agent and not devtools, because `install.packages(..., method='wget')` seems to work fine. Very weird though, you might want to report this to the R maintainers. – Neal Fultz Apr 19 '17 at 23:10
  • yes, `method="wget"` does work fine for me so install.packages is a good solution. If you modify your answer to note that "wget" method may work better for some URLs I will upvote. :) – Stefan Avey Apr 20 '17 at 15:17
10

See ?install_url in the devtools package.

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
3

Why not set up the directory in which you store the source package as a repository?

Here is an example (though you'd likely want to substitute type="source" for the type="win.binary" in the code at that link).

Community
  • 1
  • 1
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • This solves my problem. I had hoped that ``install.packages`` would be able to download and install packages outside a repository but reading the documentation closely I think this is not possible so I have accepted your answer. – orizon May 07 '13 at 07:28
0

If the url is a github repository, try: install_github()

e.g.


library(devtools)

install_github("DeveloperName/PackageName")

# e.g. install_github("cran/seoR")
stevec
  • 41,291
  • 27
  • 223
  • 311