offline installation of packages in R - empty index file generated - r

I am trying to install packages on a remote windows machine with no internet connection using source packages. I am trying to follow the instructions given in an answer to the previous question
Offline install of R package and dependencies
I have a folder with .tar.gz files for the package and it's dependencies. I run the commands
library(tools)
write_PACKAGES()
which generates the PACKAGES and PACKAGES.gz in the same folder. However, my PACKAGES file is empty (with size 0 KB).
When I try to install the package using
install.packages("<PACKAGE_NAME>", contriburl = "file:///")
(I am in the same directory as all the source files), I am getting the following error
cannot open compressed file '//PACKAGES', probable reason 'No such file or directory'
I am not sure if there is something wrong with the way I specify the path or is it because my PACKAGES file is empty that I am getting this error.
Any help here would be great!
Additional info - The remote machine is a Windows machine and I have also tried deleting the PACKAGES.gz file before installing (as recommended in the link above), but did not succeed.
Thanks!
SN248

I was able to install the package that I wanted (package name = dplyr), using the hints in the comments above. I needed to change two things
I downloaded windows binaries instead of source files, using type = "win.binary" parameter in the download.packages command.
The path in contriburl = "file:///" needed to be changed to contriburl = "file:///<ABSOLUTE_PATH_TO_FOLDER_WITH_WIN_BINARIES>"
With these changes, the package installation went successfully.
Hope it helps others.
SN248

Related

Copying old R packages from one linux server and installing them on a new server

I am trying to copy R packages from a directory on one linux server and install them on another. I started out by writing a script that would loop through a list of all the R packages I needed and install them. This worked for a majority of packages, but, since I am forced to utilize R 3.0.3, a significant number of packages are unavailable for this version of R. Meaning that R was trying to install the most recent versions of these specific packages.
I am trying to find a solution that does not involve me having to go through each package, find the version we are running on the old server, then going to CRAN and downloading the archived .tar.gz file.
Ideally, I would like to loop through the directory of R packages, make them all into .tar.gz files, move those files to the new server, and install them like that. However, I ran into the following issue when I tried to "build" one these packages.
R CMD build car
Read 1 item
* checking for file ‘car/DESCRIPTION’ ... OK
* preparing ‘car’:
* checking DESCRIPTION meta-information ... OK
Warning in file(con, "r") :
cannot open file 'man': No such file or directory
Error in file(con, "r") : cannot open the connection
ERROR
computing Rd index failed
I tried another using devtools::build('abind'), but this also failed with the same errors above.
Should I change my approach or is there something missing with what I am doing? Any help on this would be appreciated.
Your general approach won't work: tar.gz files contain the source for a package, but not all of it is installed when you install a package, so you can't recreate the tar.gz file from the installed files.
What might work if you didn't want to work with such an ancient version of R is to use Microsoft's CRAN "time machine" (https://mran.microsoft.com/timemachine), but I think it only goes back to R 3.2.3.
Copying the library might work, but binaries of those files are probably linked to system library files at particular locations, so I wouldn't trust it to be reliable.
I think your best option would be to update R to the current release (or maybe 3.5.3, the last patch release of the previous series), then just install current versions of the packages you want.
If this is impossible for some reason, then you're likely to have no choice but installing versions matching the ones you had installed. At least you can find versions automatically: the installed.packages() function returns a matrix with package name in column "Package" and its version in column "Version". Run that on the old system, then build them on the new system using the remotes::install_version() function (which claims to work on R back to 3.0.0, but I bet it hasn't been tested there lately).

How to install a R package from local folder with the dependencies installation still in same folder? [duplicate]

Suppose I need to install a number of packages on a (Linux) machine that does not have an internet connection. Let's say that I downloaded a copy of cran and burned it on a DVD that I bring to the offline location:
wget ftp://cran.r-project.org/pub/R/src/contrib/*.tar.gz
I can even add a PACKAGES file that contains an overview of all the source packages and their dependencies:
library(tools)
write_PACKAGES()
How could I use this offline to install a source package in such a way that dependencies are resolved and installed from the local files as well? For example, someone wants to install package ggplot2, which has a fairly deep dependency structure. Assume the source package of ggplot2 and all of its dependencies are available as source packages in the current working directory. If I do:
install.packages("ggplot2_0.9.1.tar.gz", repos=NULL)
This results in an error, because the dependencies are not resolved at all. Alternatively:
install.packages(list.files(pattern="*.tar.gz"), repos=NULL)
However this also ignores the dependency structure, and tries to install packages in alphabetical order, which will also fail.
I looked into available.packages and contrib.url but I just can't find an example of installing a source package from a local file including it's dependencies.
The correct answer was given by Joshua Ulrich in the comment on the question:
The key is prefixing the argument to either repos or contriburl with file://. So in Unixy systems one could do:
install.packages("ggplot2", contriburl="file:///path/to/packages/")
This assumes that all required source packages, as well as a PACKAGES index file is available in /path/to/packages. If no PACKAGES file is present, this should be generated first using:
library(tools)
write_PACKAGES("/path/to/packages/")
which will generate an index of all source packages found in this directory. Note that in the example, there are 3 slashes behind the file: prefix. The third slash indicates a path relative to the root of the file system.
The difference between the repos and contriburl argument is that repos will append another /src/contrib to the path specified, as this is usually where source packages are located on an official CRAN repository mirror.
With reference to Answer above, if installation is in Windows, then write_PACKAGES() generates two files: PACKAGES and PACKAGES.gz under '/path/to/packages/' directory where all zip files are placed. The file PACKAGES.gz should be deleted before install.packages() function is correctly able to read the lone PACKAGES file else 'cannot open compressed file' error appears.
I had the same issues during offline installation. Somehow it didn't work by command line.
I downloaded, extracted all the dependencies (Keeping check of the min version required) and pasted the folders in the library folder. This way only my problem got solved.

R: Error in install.packages : cannot open the connection

I was trying to install the package RINDSEL but I am unable to install it and I keep getting the following error:
Error in install.packages : cannot open the connection
I downloaded the package from:
rindsel_1.0_2.zip | Integrated Breeding Platform
and loaded it from the directory. Other packages from the directory can be installed but just not this one.
Is the package corrupt or could there be any other error?
I would really be grateful for any help. Thanks in advance
Rename the zip file RinSel Software into Rindsel. That's the name specified in the discription file.
Then, you can install the package in R with the command
install.packages("C:/path/to/Rindsel.zip",repos=NULL,type="win.binary")
That works fine... at first (!!!).
Problem with the Rindsel package is. It is quite old. It was build with R 2.13.1. Therefore, if you want to load the library which would be the next step to use the package in R you will get the error:
Problems building package (Error: "package has been build before R-3.0.0")
My suggestion: Contact the authors of the package and ask them if they can either provide the source file that you can build the package by yourself or if they can bundle the Rindsel package with a newer R version.
(Or you could try to hunt down an old R version and see if you can get the thing running with an old R... However, I would not seriously suggest to do that. It would probably result in conflicting dependencies with the other required packages...)
EDIT 15-02-2018: OP asked if one can build an R package with sources that are presumeably the Rindsel source files.
Yes, basically, you could do that. You would have to make a your own description and namespace file and put the source file in the R folder than invoke the command in R to build it....
But it's not neccessary with the script files provided by the link the OP posted.
OP, just run the scripts in R! It's quite easy.
Download the zip-file and extract it on your machine.
Go to that directory. The R command would be
setwd('path/to/your/directory')
Than run the R script, e.g, the KNIndex.r. It's simple:
source('KNIndex.r')
Then the script will run and produce some output / prompts.
For future readers,
I was able to fix the error by running RStudio with administrative privileges to get the command to work.
If that does not fix it, you might wish to try
Installing "r tools" if that is not installed already. That can be downloaded from
https://cran.r-project.org/bin/windows/Rtools/
Download a relevant package that you are trying to install (e.g., tidyverse_1.3.0.zip) from https://cran.rstudio.com/
and install that from local path
It can also be installed directly from the web using install.packages("https://cran.rstudio.com/bin/windows/contrib/4.0/tidyverse_1.3.0.zip")
I had the same problem. R was not able to extract and compile the package files to the default installation directory for some system-specific reasons (not R related).
I was able to fix this by specifying the installation directory of the package lib using:
install.packages("your package", lib = 'path/to your/required/installation/directory')
You can then load the package by specifying the lib.loc option while loading it:
library('your package', lib.loc='path/to your/required/installation/directory')
A better solution:
Create a new environment variable (if you are using windows) R_LIBS_USER with the following directory path/to your/required/installation/directory.
This will change the default installation directory of the packages and make it easier to load and install them without specifying the location everytime.

Can you install packages in R without imports or dependencies? [duplicate]

Suppose I need to install a number of packages on a (Linux) machine that does not have an internet connection. Let's say that I downloaded a copy of cran and burned it on a DVD that I bring to the offline location:
wget ftp://cran.r-project.org/pub/R/src/contrib/*.tar.gz
I can even add a PACKAGES file that contains an overview of all the source packages and their dependencies:
library(tools)
write_PACKAGES()
How could I use this offline to install a source package in such a way that dependencies are resolved and installed from the local files as well? For example, someone wants to install package ggplot2, which has a fairly deep dependency structure. Assume the source package of ggplot2 and all of its dependencies are available as source packages in the current working directory. If I do:
install.packages("ggplot2_0.9.1.tar.gz", repos=NULL)
This results in an error, because the dependencies are not resolved at all. Alternatively:
install.packages(list.files(pattern="*.tar.gz"), repos=NULL)
However this also ignores the dependency structure, and tries to install packages in alphabetical order, which will also fail.
I looked into available.packages and contrib.url but I just can't find an example of installing a source package from a local file including it's dependencies.
The correct answer was given by Joshua Ulrich in the comment on the question:
The key is prefixing the argument to either repos or contriburl with file://. So in Unixy systems one could do:
install.packages("ggplot2", contriburl="file:///path/to/packages/")
This assumes that all required source packages, as well as a PACKAGES index file is available in /path/to/packages. If no PACKAGES file is present, this should be generated first using:
library(tools)
write_PACKAGES("/path/to/packages/")
which will generate an index of all source packages found in this directory. Note that in the example, there are 3 slashes behind the file: prefix. The third slash indicates a path relative to the root of the file system.
The difference between the repos and contriburl argument is that repos will append another /src/contrib to the path specified, as this is usually where source packages are located on an official CRAN repository mirror.
With reference to Answer above, if installation is in Windows, then write_PACKAGES() generates two files: PACKAGES and PACKAGES.gz under '/path/to/packages/' directory where all zip files are placed. The file PACKAGES.gz should be deleted before install.packages() function is correctly able to read the lone PACKAGES file else 'cannot open compressed file' error appears.
I had the same issues during offline installation. Somehow it didn't work by command line.
I downloaded, extracted all the dependencies (Keeping check of the min version required) and pasted the folders in the library folder. This way only my problem got solved.

How to install a package not located on CRAN repository?

I am trying to use Google Trends data and have come across a few packages that are not on CRAN (GTrends, RGoogleTrends).
I like what I have seen from the RGoogleTrends package at this blog, and wanted to give it a try. The RGoogleTrends package is located here: http://www.omegahat.org/RGoogleTrends/
First of all, I am using a Windows OS and there is an uption in my R console:
>Packages>Install package(s) from local zip drives ...
This results in the following:
> utils:::menuInstallLocal()
Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) :
cannot open the connection
In addition: Warning messages:
1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file
2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) :
cannot open compressed file 'RGoogleTrends_0.2-1.tar.gz/DESCRIPTION', probable reason 'No such file or directory'
I'm guessing this has to do with the fact that the file is as a .gz and not a .zip file.
So, I unzipped the .gz file outside of R and then zipped it into a .zip file (there's got to be a better way). Now I can install the .zip file, but when I try and load it with library, the following error occurs:
> library(RGoogleTrends)
Error in library(RGoogleTrends) :
‘RGoogleTrends’ is not a valid installed package
What am I doing wrong here?
You will need R version 3 for this, which you can get here for example:
http://cran.cnr.berkeley.edu/bin/windows/base/R-3.0.1-win.exe
Then open R and type:
install.packages("devtools")
require(devtools)
install_url("http://www.omegahat.org/RGoogleTrends/RGoogleTrends_0.2-1.tar.gz")
require(RGoogleTrends)
ls("package:RGoogleTrends")
You may get few warnings in the process. Ignore them. you should then be able to use the package.
I think a package builds differently for linux than to windows so a .gz version can't be converted to .zip
This link indicates you should be able to use just the unzipped version...
http://decisionstats.com/2013/04/26/using-a-linux-only-package-in-windows-rstats/
The comment in it suggests devtools or Rtools, both of which will allow direct installation from the gz file
To unzip and use directly
Extract from tar.gz to .tar
Extract from .tar
Set the working directory to the R subfolder e.g. Setwd( "C:\\Users\\x\\Documents\\RGoogleTrends_0.2-1.tar\\RGoogleTrends_0.2-1\\RGoogleTrends\\R")
Load all functions for (i in list.files()){source(i)}
To use devtools
Install devtools
library("devtools")
Setwd to folder containing .tar.gz file
install("RGoogleTrends_0.2-1.tar.gz")
To use Rtools
Download correct version from http://cran.r-project.org/bin/windows/Rtools/
Install from the .exe
Check whether you need to anything in http://cran.r-project.org/bin/windows/Rtools/Rtools.txt
Run R from your command line (cmd into search in start) - see
Setwd to folder containing .tar.gz file
R CMD INSTALL *.tar.gz
My preferred approach is devtools
I was having all sorts of issues with errors like:
not supported in current version
cannot find DEPENDENCIES
cannot unzip
If you are running windows and installed for all users and are running as a normal user (which you should be for all sorts of reasons) installing packages is interesting.
What I ended up doing was
close R
open R as admin
load base package
I had already downloaded the packages so I could install offline and they were in f:\software\rcontrib
then run:
files=list.files(path="f:/software/rcontrib",pattern="*.zip",include.dirs=TRUE)
for (i in seq(along=files)){install.packages(files[i],repos=NULL)}
This will bulk load packages from the local directory / common file share / non-internet location.
Then you can exit R. Running as any user on the machine you should be able to use the packages.
This will hopefully save people the couple of hours I wasted trying to bulk load and overcome errors in R which were actually windows security.

Resources