Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

r - How to install a package from a download zip file

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:UsersDocumentsRwin-library3.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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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=";"))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...