installing package from zip file with no tar.gz [duplicate] - r

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

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

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

Hard to believe this don't have a clear, simple and accurate answer.
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.
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.

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.

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

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.

Download the package.tar.gz
Then from command line :
R CMD INSTALL package.tar.gz

Related

Trouble installing package ‘export’ after upgrading R version. Is there an alternative to this package? [duplicate]

I typed the following in the R command line:
install.packages("RecordLinkage")
I got the following error:
Warning in install.packages :
package ‘RecordLinkage’ is not available (for R version 3.1.0)
However, one of my coworkers did the exact same thing on the exact same version of R (3.1.0) and it worked. In addition, I've managed to install other packages successfully.
Any idea why this does not work? Any help would be greatly appreciated.
The package has been archived, so you will have to install from an archive.
I know this because the package home page at http://cran.r-project.org/web/packages/RecordLinkage/index.html tells me:
Package ‘RecordLinkage’ was removed from the CRAN repository.
Formerly available versions can be obtained from the archive.
Archived on 2015-05-31 as memory access errors were not corrected.
By following the link to archives (http://cran.r-project.org/src/contrib/Archive/RecordLinkage) I get a list of all old versions:
[ ] RecordLinkage_0.3-5.tar.gz 12-Sep-2011 18:04 688K
[ ] RecordLinkage_0.4-1.tar.gz 12-Jan-2012 09:39 676K
So now I know the version number of the most recent version. The way forward is to download the tarball, install all package dependencies and then install the package from the local downloaded file.
Try this:
# Download package tarball from CRAN archive
url <- "http://cran.r-project.org/src/contrib/Archive/RecordLinkage/RecordLinkage_0.4-1.tar.gz"
pkgFile <- "RecordLinkage_0.4-1.tar.gz"
download.file(url = url, destfile = pkgFile)
# Expand the zip file using whatever system functions are preferred
# look at the DESCRIPTION file in the expanded package directory
# Install dependencies list in the DESCRIPTION file
install.packages(c("ada", "ipred", "evd"))
# Install package
install.packages(pkgs=pkgFile, type="source", repos=NULL)
# Delete package tarball
unlink(pkgFile)
Note:
This will only work if you have the build tools installed on your machine. On Linux this will be the case. But on Windows you will have to install RTools if you don't have it already. And on OS X (Mac) you will have to install XCode and the associated command line tools.
Also this solution from the Rstudio blog
require(devtools)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")
https://support.rstudio.com/hc/en-us/articles/219949047-Installing-older-versions-of-packages
If using Rstudio, select "install from Package Archive File(.zip;.tar.gz)" in "Install Packages" window.
On linux this is simply:
sudo su - -c "R -e \"devtools::install_url('https://cran.r-project.org/src/contrib/RecordLinkage_0.4-10.tar.gz')\""

package 'lubridate' installation error: compilation failed for package 'lubridate' [duplicate]

A friend sent me along this great tutorial on webscraping The New York Times with R. I would really love to try it. However, the first step is to install a package called [RJSONIO][2] from source.
I know R reasonably well, but I have no idea how to install a package from source.
I'm running macOS (OS X).
If you have the file locally, then use install.packages() and set the repos=NULL:
install.packages(path_to_file, repos = NULL, type="source")
Where path_to_file would represent the full path and file name:
On Windows it will look something like this: "C:\\RJSONIO_0.2-3.tar.gz".
On UNIX it will look like this: "/home/blah/RJSONIO_0.2-3.tar.gz".
Download the source package, open Terminal.app, navigate to the directory where you currently have the file, and then execute:
R CMD INSTALL RJSONIO_0.2-3.tar.gz
Do note that this will only succeed when either: a) the package does not need compilation or b) the needed system tools for compilation are present. See: R for Mac OS X
You can install directly from the repository (note the type="source"):
install.packages("RJSONIO", repos = "http://www.omegahat.org/R", type="source")
A supplementarily handy (but trivial) tip for installing older version of packages from source.
First, if you call "install.packages", it always installs the latest package from repo. If you want to install the older version of packages, say for compatibility, you can call install.packages("url_to_source", repo=NULL, type="source"). For example:
install.packages("http://cran.r-project.org/src/contrib/Archive/RNetLogo/RNetLogo_0.9-6.tar.gz", repo=NULL, type="source")
Without manually downloading packages to the local disk and switching to the command line or installing from local disk, I found it is very convenient and simplify the call (one-step).
Plus: you can use this trick with devtools library's dev_mode, in order to manage different versions of packages:
Reference: doc devtools
From CRAN, you can install directly from a GitHub repository address. So if you want the package at https://github.com/twitter/AnomalyDetection, using
library(devtools)
install_github("twitter/AnomalyDetection")
does the trick.
In addition, you can build the binary package using the --binary option.
R CMD build --binary RJSONIO_0.2-3.tar.gz

R package ‘ElemStatLearn’ is not available (for R version 3.6.3) is there any alternative available [duplicate]

I typed the following in the R command line:
install.packages("RecordLinkage")
I got the following error:
Warning in install.packages :
package ‘RecordLinkage’ is not available (for R version 3.1.0)
However, one of my coworkers did the exact same thing on the exact same version of R (3.1.0) and it worked. In addition, I've managed to install other packages successfully.
Any idea why this does not work? Any help would be greatly appreciated.
The package has been archived, so you will have to install from an archive.
I know this because the package home page at http://cran.r-project.org/web/packages/RecordLinkage/index.html tells me:
Package ‘RecordLinkage’ was removed from the CRAN repository.
Formerly available versions can be obtained from the archive.
Archived on 2015-05-31 as memory access errors were not corrected.
By following the link to archives (http://cran.r-project.org/src/contrib/Archive/RecordLinkage) I get a list of all old versions:
[ ] RecordLinkage_0.3-5.tar.gz 12-Sep-2011 18:04 688K
[ ] RecordLinkage_0.4-1.tar.gz 12-Jan-2012 09:39 676K
So now I know the version number of the most recent version. The way forward is to download the tarball, install all package dependencies and then install the package from the local downloaded file.
Try this:
# Download package tarball from CRAN archive
url <- "http://cran.r-project.org/src/contrib/Archive/RecordLinkage/RecordLinkage_0.4-1.tar.gz"
pkgFile <- "RecordLinkage_0.4-1.tar.gz"
download.file(url = url, destfile = pkgFile)
# Expand the zip file using whatever system functions are preferred
# look at the DESCRIPTION file in the expanded package directory
# Install dependencies list in the DESCRIPTION file
install.packages(c("ada", "ipred", "evd"))
# Install package
install.packages(pkgs=pkgFile, type="source", repos=NULL)
# Delete package tarball
unlink(pkgFile)
Note:
This will only work if you have the build tools installed on your machine. On Linux this will be the case. But on Windows you will have to install RTools if you don't have it already. And on OS X (Mac) you will have to install XCode and the associated command line tools.
Also this solution from the Rstudio blog
require(devtools)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")
https://support.rstudio.com/hc/en-us/articles/219949047-Installing-older-versions-of-packages
If using Rstudio, select "install from Package Archive File(.zip;.tar.gz)" in "Install Packages" window.
On linux this is simply:
sudo su - -c "R -e \"devtools::install_url('https://cran.r-project.org/src/contrib/RecordLinkage_0.4-10.tar.gz')\""

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:\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
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=";"))
Try install.packages('C:/Users/Desktop/rvest-master.zip', repos = NULL, type = "win.binary"). (Untested)
Hard to believe this don't have a clear, simple and accurate answer.
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.
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.
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.
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
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.
Download the package.tar.gz
Then from command line :
R CMD INSTALL package.tar.gz

Making R packages for installation by install.packages()

What is the difference between .tar.gz or .tgz files installed by R CMD install and install.packages()? I have made an example package with R CMD build, which I can currently install with R CMD install mypackage.tar.gz - and it works fine. I want to be able to install it through the install.packages() function (with a call like install.packages("mypackage.tar.gz",repos=NULL)). What additional steps do I need to take?
It depends on your OS. On Linux you can install your .tar.gz package with the command you specify. If you are on Mac OS X, you need to specify that you are installing from source package and not binary (see ?install.packages on a Mac). As Dirk said the .tgz packages are binary builds for Mac and you can build them on a Mac.
If you want to build the package for Windows see http://win-builder.r-project.org/, which is a web service for building binary packages from source.
If you are planning to submit your package to CRAN, but wan't to test is first see Rforge
I think the .tgz is the binary package on OS X, just like windows gets a binary .zip. Either one results from R CMD build.
So when you write "have made an example package with R CMD build, which I can currently install with R CMD install mypackage.tar.gz" you are inconsistent as the .tar.gz was the source and the result of the R CMD BUILD step. Start with the .tar.gz sources, make sure R CMD check and R CMD INSTALL work on them and then try R CMD binary.
Lastly, for install.packages() you need both the binary packages created by R CMD build --binary and a web-based repository containing file PACKAGES etc --- and as help(install.packages) says, see the R Installation and Administration manual for how to set up a repository.

Resources