devtools::install_git 无法在 Depends 或 Imports 中安装包的依赖项

devtools::install_git fails to install dependencies of packages in Depends or Imports

我有一个依赖包 extrafont 的包。如果用户系统上不存在 extrafont 及其依赖项 Rttf2pt1,则我的软件包安装失败。我的包的描述文件中有 extrafont 作为 "Depends"。当我 运行 devtools::install_git() 从 URL 安装我的包时,输出终止于:

** preparing package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  there is no package called 'Rttf2pt1'
Error : package 'extrafont' could not be loaded
ERROR: lazy loading failed for package 'tntpr'
* removing 'C:/Users/SFirke/Documents/R/win-library/3.3/tntpr'

看起来 extrafont 安装正常,但无法正常工作,因为缺少 Rttf2pt1。当我将 Rttf2pt1 添加到我的 DESCRIPTION 文件中的 Depends 列表时,安装成功,安装了 extrafontRttf2pt1 以及我的包。

为什么我需要在依赖列表中添加 Rttf2pt1?它出现在 extrafont 包的描述文件中的 "Imports" 列表中:

Depends:
    R (>= 2.15)
Imports:
    extrafontdb,
    grDevices,
    utils,
    Rttf2pt1

附加信息

当我 运行 devtools::install_git("https://myurl.com/tntpr.git", dependencies = TRUE) 时,我得到以下输出。它从 GitHub 安装 dplyr,然后安装 extrafonts,然后无法加载我的包:

Installing tntpr
Downloading GitHub repo hadley/dplyr@master
from URL https://api.github.com/repos/hadley/dplyr/zipball/master
Installing dplyr
"C:/PROGRA~1/R/R-33~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  "C:/Users/SFirke/AppData/Local/Temp/RtmpMlRSSR/devtools3dfc4e39620/hadley-dplyr-5902277" --library="C:/Users/SFirke/Documents/R/win-library/3.3" --install-tests 

* installing *source* package 'dplyr' ...
** libs

*** arch - i386
C:/RBuildTools/3.4/mingw_32/bin/g++  -I"C:/PROGRA~1/R/R-33~1.2/include" -DNDEBUG -I../inst/include -DCOMPILING_DPLYR   -I"C:/Users/SFirke/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/SFirke/Documents/R/win-library/3.3/BH/include" -I"C:/Users/SFirke/Documents/R/win-library/3.3/bindrcpp/include" -I"C:/Users/SFirke/Documents/R/win-library/3.3/plogr/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
<--- lots more lines like this ^^^^^ --->
** R
** data
*** moving datasets to lazyload DB
** inst
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (dplyr)
Installing 1 package: extrafont
Installing package into ‘C:/Users/SFirke/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/extrafont_0.17.zip'
Content type 'application/zip' length 34323 bytes (33 KB)
downloaded 33 KB

package ‘extrafont’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\SFirke\AppData\Local\Temp\RtmpMlRSSR\downloaded_packages
"C:/PROGRA~1/R/R-33~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL "C:/Users/SFirke/AppData/Local/Temp/RtmpMlRSSR/file3dfc4a973a21"  \
  --library="C:/Users/SFirke/Documents/R/win-library/3.3" --install-tests 

* installing *source* package 'tntpr' ...
** R
** data
*** moving datasets to lazyload DB
** inst
** tests
** preparing package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  there is no package called 'Rttf2pt1'
Error : package 'extrafont' could not be loaded
ERROR: lazy loading failed for package 'tntpr'
* removing 'C:/Users/SFirke/Documents/R/win-library/3.3/tntpr'
Error: Command failed (1)

问题:存在特定于 Windows 的问题,其中 both devtools 1.12.0(当前 CRAN 版本) devtools 1.12.0.9000 的当前开发版本在嵌套/递归依赖方面存在问题(即,假设您的包 A 依赖于包 B,而包 B 又依赖于包 C;devtools 函数 install_*(A)不会安装C).

请参阅此 comment re: the development version and the top parts of the thread that note problems with the CRAN version as well and this package's workaround of manually specifying sub-dependencies 进行安装。

解决方案:我安装了旧版本的 devtools 1.11.1(2016 年 4 月发布),即使缺少依赖项,它也适用于我上面的 install_git() 调用需要安装。

install.packages("devtools") # from CRAN
devtools::install_version("devtools", version = "1.11.1", repos = "http://cran.us.r-project.org") # get the old version

然后重新启动 R 并按预期使用 devtools。