How to install a package not located on CRAN repository?
Asked Answered
S

3

6

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?

Schramm answered 21/6, 2013 at 8:54 Comment(4)
The term you're looking for is "how to build a package in windows". A web search scores more than enough hits. In short, you should install Rtools and run R CMD INSTALL --build yourfile.tar.gz.Cist
@RomanLuštrik - If I'm able to open .gzfiles outside of R, then I assume there should be a way to load the package without needing to install another program - correct? p.s. I have cygwin installed, but have never run R through it.Schramm
Did you try install.packages(packageName, repos = "http://www.omegahat.org/R", type = "source") as suggested at omegahat.org ?Hardly
@Hardly - that doesn't work for me. "Error in install.packages(RGoogleTrends, repos = "omegahat.org/R", : object 'RGoogleTrends' not found "Schramm
P
14

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.

Pickerel answered 21/6, 2013 at 9:54 Comment(1)
Thanks Dimitrii - this worked great. The package installed easily enough - getting it to work properly seems t be the next challenge, Cheers.Schramm
C
4

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

  1. Extract from tar.gz to .tar
  2. Extract from .tar
  3. 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")
  4. Load all functions for (i in list.files()){source(i)}

To use devtools

  1. Install devtools
  2. library("devtools")
  3. Setwd to folder containing .tar.gz file
  4. install("RGoogleTrends_0.2-1.tar.gz")

To use Rtools

  1. Download correct version from http://cran.r-project.org/bin/windows/Rtools/
  2. Install from the .exe
  3. Check whether you need to anything in http://cran.r-project.org/bin/windows/Rtools/Rtools.txt
  4. Run R from your command line (cmd into search in start) - see
  5. Setwd to folder containing .tar.gz file
  6. R CMD INSTALL *.tar.gz

My preferred approach is devtools

Crutch answered 21/6, 2013 at 9:11 Comment(2)
I incorporated some how tos for youCrutch
just to add a way using devtools (because the option here wasn't working for me), I unzipped (twice) the tar.gz and use install with the unzipped folder. (R 3.3.0 on Windows 7 with devtools_1.12.0 and Rtools 3.4.0.1962)Claudicant
D
1

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.

Domineering answered 30/1, 2015 at 20:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.