How to install a package not located on CRAN repository? - r

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.

Related

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.

offline installation of packages in R - empty index file generated

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

Error installing .zip file with R package or library

I am trying to install the R package MixeR 2003 by Batagelj and Bren . This is not in CRAN, but is accessible on this website as a downloadable zip file containing an R file (MixeR.R), a dataset (Glac.dat) and 3 pdf's.
I downloaded the zip file, and placed it in my R directory. After that, I attempted to install it from within RStudio using the drop-down menus Tools > Install Packages > Package Archive File (.zip; .tar.gz) > MixeR.zip, getting the following error message:
install.packages("~/R/MixeR.zip", repos = NULL, type = "win.binary")
Installing package into ‘C:/Users/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
Warning in install.packages :
cannot open compressed file 'MixeR/DESCRIPTION', probable reason 'No such file or directory'
Error in install.packages : cannot open the connection
What am I doing wrong, and how can I install this package?
It may very well be that it is actually not a package, but rather a 'library', in which case I would appreciate guidance as to how to make the functions and datasets in it accessible to the R session.
If you download and extract you'll see that that it's some pdfs, a .dat file, and a single R script that contains a bunch of functions.
Likely you just want to source the script so you want to extract the zip archive and then use source on MixeR.R
source("path/to/MixeRArchive/MixeR.R")
Alternatively they do host that file on their website directly so you could just read it from the internet directly
source("http://vlado.fmf.uni-lj.si/pub/MixeR/MixeR.R")
Either way will read the functions directly into your global environment since it isn't an actual package with its own namespace.

Installing gdata in R

I tried to install package gdata with the following command, but got the message that follows:
install.packages(pkgs="gdata")
Warning in install.packages(pkgs = "gdata") :
'lib = "C:/Program Files/R/R-3.1.3/library"' is not writable
Error in install.packages(pkgs = "gdata") : unable to install packages
Seems the directory "library" should be writable, so what did I do wrong?
You can install in a custom folder by specifying the lib argument of install.packages. Try something like lib = "C:/Users/you/Documents/R/3.1.3/" or whatever folder you have writable.
If R is installed on a Remote Desktop, or somewhere else where R is having difficulty automatically installing those folders, you will need to specify where to put the files. The first step will be creating these folders, for example in your C:/ or D:/ drive. Preferably create an R folder, with a version folder (3.1.3) that you will be using. To know which version of R your using if using R studio, hold control while opening R studio.
Once these folders are created, just use the following code, inputting your path to the version folder (3.1.3). For example:
lib = "D:/R/3.1.3"
install.packages("gdata", lib)
And then to load your package.
library("gdata", lib.loc= lib)

Install "old package" (not available on cran web site) on R 2.15 on OS X 10.8

I'm new to R and I'm trying to install the packages that are listed on this web page: http://web.cbio.uct.ac.za/~renaud/CRAN but that are now available on cran website anymore.
When I try to use the "package installer", R is looking for an osx directory that does not exist on this web site.
When I download the files on my hard drive either as a .tar file or uncompress the file and then compress it as a .tgz file, I get this error message:
Error: file ‘/Users/XXXXXX/Downloads/NMF.tgz’ is not an OS X binary package.
Any hint on how to install this package on R, and/or what is the way to (re)compile it, so it would be recognized by R on OS X 10.8?
I had this problem too, and found a remedy at:
http://www.highstat.com/Installing%20Library%20Packages%20that%20are%20not%20on%20the%20CRAN%20Website.pdf
In essence, you can de-compress the .tgz file, and (on a Mac) put the resulting directory in the following location:
/Library/Frameworks/R.framework/Resources/library
Then load the package into R using the standard library() command.
As the referenced PDF pointed out, this approach may not work if the package includes source, but it's worth trying for you, unless you're certain it does contain source.

Resources