27

I have download this package as a zip file.

Is it possible to install it from R console using this zip or unzip version to a specific path?

install.packages("C:/Users/Desktop/rvest-master.zip', lib='C:/R/R-3.2.1',repos = NULL)

I type the previous command but is not working

> setwd("C:/Users/Desktop/")
> unzip("rvest-master.zip")
> file.rename("rvest-master", "rvest")
[1] TRUE
> shell("R CMD build rvest")
Warning messages:
1: running command ' /c R CMD build rvest' had status 127 
2: In shell("R CMD build rvest") :
  'R CMD build rvest' execution failed with error code 127
> install.packages("rvest_0.2.0.9000.tar.gz", repos = NULL)
Installing package into ‘C:/Users/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
Warning: invalid package 'rvest_0.2.0.9000.tar.gz'
Error: ERROR: no packages specified
Warning messages:
1: running command '"C:/R/R-3.2.1/bin/x64/R" CMD INSTALL -l "C:\Users\Documents\R\win-library\3.2" "rvest_0.2.0.9000.tar.gz"' had status 1 
2: In install.packages("rvest_0.2.0.9000.tar.gz", repos = NULL) :
  installation of package ‘rvest_0.2.0.9000.tar.gz’ had non-zero exit status

In the previous line are the results from the answer

angs
  • 341
  • 3
  • 5
  • 13
  • Possible repeat: http://stackoverflow.com/questions/1474081/how-do-i-install-an-r-package-from-source – cr1msonB1ade Jun 22 '15 at 20:26
  • What does "is not working" mean exactly? Did you get an error message? – MrFlick Jun 22 '15 at 20:31
  • @cr1msonB1ade please could you advice me what I am doing wrong in the command? – angs Jun 22 '15 at 20:31
  • 2
    I would first fix your quotation marks (first one is double second is single) and second I would try adding `type='source'`. What is the error that you are getting? – cr1msonB1ade Jun 22 '15 at 20:33
  • Why aren't you following the install directions at that linked website? – IRTFM Jun 22 '15 at 20:35
  • @cr1msonB1ade it works but when I type library(rvest) it gives Error in library(rvest) : there is no package called ‘rvest’ Is there any way to find where the R package from installation process go and installed? – angs Jun 22 '15 at 20:37
  • I guess your installed package is in the temporary directory and not R package directory. One way is to copy the folder from that directory to R package directory. – user227710 Jun 22 '15 at 20:39
  • @user227710 and how can I find the R package directory? – angs Jun 22 '15 at 20:47
  • Mine is `C:\Users\myname\Documents\R\win-library` and I am using Windows 8. – user227710 Jun 22 '15 at 20:48
  • 1
    The `shell()` command doesn't work because R is not on your system search path. You can check this within R by typing `Sys.getenv("PATH")` and seeing whether your R directory is included. If not, you need to add it ([instructions](http://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them)) and then restart R. – Thomas Jun 22 '15 at 20:51

7 Answers7

49

You have downloaded a zip of the source of a package. This is not the standard packaging of a package source nor is it a standard Windows binary (i.e., a built package distributed as a .zip, as from CRAN).

The easiest thing for you to do is to install this package directly from Github using devtools:

library("devtools")
install_github("hadley/rvest")

If you decide to install it locally, you need to unzip the package directory, build it from the command line using R CMD build rvest and then install either using R CMD INSTALL or from within R using the command you already have (but performed on the built "tarball"). Here's how you could do all of this from within R:

setwd("C:/Users/Desktop/")
unzip("rvest-master.zip")
file.rename("rvest-master", "rvest")
shell("R CMD build rvest")

This will make a tarball version of the package in the current directory. You can then install that with

install.packages("rvest_0.2.0.9000.tar.gz", repos = NULL)

Since the version number is merged into the tarball name, it may not always be obvious what the new file might be called. You can use list.files() to grab the new tarball.

install.packages(list.files(pattern="rvest*.tar.gz"), repos = NULL)

If the shell() line gives you an error like this

'R' is not recognized as an internal or external command

You need to make sure that R is in your shell path. You can add it with something like

Sys.setenv(PATH=paste(R.home("bin"), Sys.getenv("PATH"), sep=";"))
MrFlick
  • 195,160
  • 17
  • 277
  • 295
Thomas
  • 43,637
  • 12
  • 109
  • 140
24

Try install.packages('C:/Users/Desktop/rvest-master.zip', repos = NULL, type = "win.binary"). (Untested)

RobertMyles
  • 2,673
  • 3
  • 30
  • 45
  • 2
    works great. also you can just copy link address directly from cran. Here is an example. ```install.packages('https://cran.r-project.org/bin/windows/contrib/3.3/proxy_0.4-20.zip', repos = NULL, type = "win.binary")``` – Ahdee Feb 11 '18 at 01:10
  • 2
    I highly doubt this works great. The OP downloaded a githb repo zip, this is for win binary package, only CRAN host this kind of file. – dracodoc Oct 23 '19 at 23:17
7

Hard to believe this don't have a clear, simple and accurate answer.

  1. The zip you downloaded from github by clicking "download as zip" is a pack of that repo, which is not the standard R source package format like CRAN hosted. Thus the methods that work with CRAN source tar.gz will not work with this kind of zip.
  2. The simplest method is to use devtools::install_local. If devtools bring too many dependencies to you, you can use remotes::install_local which is the real function and have much less dependencies.
Matt S
  • 15
  • 7
dracodoc
  • 2,603
  • 1
  • 23
  • 33
2

If this is the zip of the source of a package, and the R core install.packages() doesn't work, then you can use install_local() from the devtools package.

I often do this when installing packages from GitHub as getting curl through our proxy is painful. So I download the source zip and install like this.

anotherfred
  • 1,330
  • 19
  • 25
1

On Windows 7 and R 3.5.3 I had to extract the zip, repackage it as .tar.gz and then install it using the command below. When installing the zip the package will not be indexed by R.

install.packages("C:/your-package.tar.gz", repos = NULL, type = "win.binary", lib="C:/Users/username/Documents/R/R-3.5.3/library")

Environment

version _
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.3
year 2019
month 03
day 11
svn rev 76217
language R
version.string R version 3.5.3 (2019-03-11) nickname Great Truth

JasperJ
  • 1,192
  • 1
  • 12
  • 23
-1

You can make use of install_local method in devtools package. Unzip the zipped file and specify the folder which contains DESCRIPTION file of the package in the path argument or you can also make use of subdir argument.

If it doesn't explains, I will post an example... Let me know.

-2

Download the package.tar.gz

Then from command line :

R CMD INSTALL package.tar.gz
jmary
  • 257
  • 4
  • 11