简体   繁体   English

如何安装不在CRAN存储库中的软件包?

[英]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 ). 我正在尝试使用Google趋势数据,并且遇到了一些不在CRAN上的软件包( GTrendsRGoogleTrends )。

I like what I have seen from the RGoogleTrends package at this blog , and wanted to give it a try. 我喜欢我在本博客的RGoogleTrends软件包看到的内容,并希望尝试一下。 The RGoogleTrends package is located here: http://www.omegahat.org/RGoogleTrends/ RGoogleTrends包位于: http ://www.omegahat.org/RGoogleTrends/

First of all, I am using a Windows OS and there is an uption in my R console: 首先,我使用的是Windows操作系统,我的R控制台中有一个提升:

>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. 我猜这与文件是.gz而不是.zip文件的事实有关。

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). 因此,我将.gz文件解压缩到R之外,然后将其压缩成.zip文件(必须有更好的方法)。 Now I can install the .zip file, but when I try and load it with library , the following error occurs: 现在我可以安装.zip文件,但是当我尝试使用library加载它时,会发生以下错误:

> 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 你需要R版本3,例如: http//cran.cnr.berkeley.edu/bin/windows/base/R-3.0.1-win.exe

Then open R and type: 然后打开R并键入:

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 我认为一个包的构建方式不同于linux而不是windows,因此.gz版本无法转换为.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/ 此链接表明您应该只能使用解压缩版本... 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 其中的注释表明devtools或Rtools,两者都允许从gz文件直接安装

To unzip and use directly 直接解压缩和使用

  1. Extract from tar.gz to .tar 从tar.gz中提取到.tar
  2. Extract from .tar 从.tar中提取
  3. Set the working directory to the R subfolder eg Setwd( "C:\\\\Users\\\\x\\\\Documents\\\\RGoogleTrends_0.2-1.tar\\\\RGoogleTrends_0.2-1\\\\RGoogleTrends\\\\R") 将工作目录设置为R子文件夹,例如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)} 加载for (i in list.files()){source(i)}所有函数

To use devtools 使用devtools

  1. Install devtools 安装devtools
  2. library("devtools")
  3. Setwd to folder containing .tar.gz file Setwd到包含.tar.gz文件的文件夹
  4. install("RGoogleTrends_0.2-1.tar.gz")

To use Rtools 使用Rtools

  1. Download correct version from http://cran.r-project.org/bin/windows/Rtools/ http://cran.r-project.org/bin/windows/Rtools/下载正确的版本
  2. Install from the .exe 从.exe安装
  3. Check whether you need to anything in http://cran.r-project.org/bin/windows/Rtools/Rtools.txt http://cran.r-project.org/bin/windows/Rtools/Rtools.txt中检查是否需要任何内容
  4. Run R from your command line (cmd into search in start) - see 从命令行运行R(cmd到开始搜索) - 请参阅
  5. Setwd to folder containing .tar.gz file Setwd到包含.tar.gz文件的文件夹
  6. R CMD INSTALL *.tar.gz R CMD INSTALL * .tar.gz

My preferred approach is devtools 我首选的方法是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. 如果您正在运行Windows并为所有用户安装并以普通用户身份运行(您应该出于各种原因)安装软件包很有意思。

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 我已经下载了这些软件包,因此我可以离线安装,它们位于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. 这将从本地目录/公共文件共享/非Internet位置批量加载包。

Then you can exit R. Running as any user on the machine you should be able to use the packages. 然后你可以退出R.作为机器上的任何用户运行你应该能够使用这些包。

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. 这将有希望为人们节省几个小时,我浪费了大量加载并克服R中实际上是Windows安全性的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM