7

我刚刚创建了一个包 ( RTIO) 和一个包存储库 ( Q:/Integrated Planning/R),这是一个公司网络驱动器。

我已将包裹放入文件夹:

Q:/Integrated Planning/R/bin/windows/contrib/2.15/RTIO_0.1-2.zip

根据 Dirk 在SO 中的说明,我运行了以下命令:

> setwd("Q:/Integrated Planning/R/bin/windows/contrib/2.15")
> tools::write_PACKAGES(".", type="win.binary")
> list.files()
[1] "PACKAGES"       "PACKAGES.gz"    "RTIO_0.1-2.zip"
>

使用下面的代码,我已将本地存储库添加到我的存储库列表中(我会让其他用户也这样做):

options(repos = c(getOption("repos"), RioTintoIronOre = "Q:/Integrated Planning/R"))

现在尝试安装我的包我得到一个错误:

> install.packages("RTIO")
Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’
(as ‘lib’ is unspecified)
Warning in install.packages :
  unable to access index for repository Q:/Integrated Planning/R/bin/windows/contrib/2.15
Warning in install.packages :
  unable to access index for repository Q:/Integrated Planning/R/bin/windows/contrib/2.15
Warning in install.packages :
  unable to access index for repository Q:/Integrated Planning/R/bin/windows/contrib/2.15
Warning in install.packages :
  package ‘RTIO’ is not available (for R version 2.15.1)

unable to access index for repository告诉我什么?我该如何解决?

我真正想做的是,在 Windows 下并使用 RStudio 作为 IDE,让其他内部 R 用户添加这个包 repo,以便他们能够运行类似的命令install.packages("RTIO")update.packages() 获取包的新版本(并且可能还有能够使用 IDE 通过 GUI 管理包)。


更新:

感谢agstudy的回答,我更近了一步。这是我得到的输出。

> getOption("repos")
                                CRAN                            CRANextra 
    "http://cran.ms.unimelb.edu.au/" "http://www.stats.ox.ac.uk/pub/RWin" 
> setRepositories(addURLs=c(RioTintoIronOre = "file://Q:/Integrated Planning/R"))
--- Please select repositories for use in this session ---


1: + CRAN
2: + CRAN (extras)
3:   BioC software
4:   BioC annotation
5:   BioC experiment
6:   BioC extra
7:   Omegahat
8:   R-Forge
9:   rforge.net

Enter one or more numbers separated by spaces, or an empty line to cancel
1: 
> getOption("repos")
                  RioTintoIronOre 
"file://Q:/Integrated Planning/R" 
> install.packages("RTIO")
Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’
(as ‘lib’ is unspecified)
Warning in install.packages :
  cannot open compressed file '//Q:/Integrated Planning/R/bin/windows/contrib/2.15/PACKAGES', probable reason 'No such file or directory'
Error in install.packages : cannot open the connection

跟进问题:

  1. 为什么在使用时提示我选择存储库setRepositories()

  2. 当我在不输入数字的情况下点击“输入”并检查getOption("repos")它只显示File://Q:/Integrated Planning/R存储库。这是为什么?

  3. 当我这样做install.packges("RTIO")时,它似乎找到了文件,但给出了警告cannot open compressed file和错误cannot open the connection。注意list.files()上面的输出。知道为什么吗?

4

2 回答 2

4

为了避免此消息:

Warning in install.packages : cannot open compressed file '//Q:/Integrated Planning/R/bin/windows/contrib/2.15/PACKAGES', probable reason 'No such file or directory'



//在指定 url 时 尝试删除setRepositories

> setwd("Q:/Integrated Planning/R/bin/windows/contrib/2.15")
> tools::write_PACKAGES(".", type="win.binary")
> setRepositories(addURLs=c(RioTintoIronOre = "file:Q:/Integrated Planning/R"))
> install.packages("RTIO")
于 2013-09-18T07:25:42.587 回答
2

您收到警告unable to access index for repository 是因为install.packages尝试在远程存储库(非本地)中访问您的自定义包。

要解决此问题,您需要将本地存储库添加到您的 R-options repos。您需要将其添加为 url 路径而不是文件路径。类似文件://

做这样的事情:

      setRepositories(addURLs=c(lRioTintoIronOre = "file://Q:/Integrated Planning/R"))

要检查一切是否正确,以下必须返回 TRUE:

    repos <- contrib.url(getOption('repos'))
    length(grep("^file:", repos)) > 0L 
于 2012-12-11T06:55:03.170 回答