当我重建自定义 R 包时,依赖项下列出的包不会安装
Package listed under depends does not install when I rebuild a custom R Package
我正在重建一个自定义 R 程序包,它在 DESCRIPTION 文件的 Depends 行中包含其他库中的 RcppArmadillo。
我是 运行 R 3.5.1。当我在 RStudio 中重建包时,出现错误:
ERROR: dependency ‘RcppArmadillo’ is not available for package 'custom package name'
根据 R Packages book,重建包时必须安装 Depends/Imports 下的包。
解决方案
改用devtools::install()
。
说明
根据 RStudio website,
The Build and Reload command performs several steps in sequence to ensure a clean and correct result:
1.Unloads any existing version of the package (including shared libraries ifnecessary).
2.Builds and installs the package using R CMD INSTALL.
3.Restarts the underlying R session to ensure a clean environment for re-loading the package.
4.Reloads the package in the new R session by executing the library function.
虽然 devtools::install()
将为您安装依赖项 -- 来自 help("install.packages")
:
Uses R CMD INSTALL to install the package. Will also try to install
dependencies of the package from CRAN, if they're not already
installed.
(强调)单独 R CMD INSTALL
不是这种情况(请参阅 R 中的 ?INSTALL
或命令行中的 R CMD INSTALL --help
等 - 没有提及安装所需的依赖项)。
于是,出现了语言
In fact, any time your package is installed, those packages will, if
not already present, be installed on your computer
(devtools::load_all() also checks that the packages are installed).
来自 Hadley 的 R Packages is a little specific; it does not pertain to using R CMD INSTALL
(which RStudio's build function apparently uses), but does work for devtools::install()
. It's a matter of personal taste, but honestly I highly recommend using devtools
在您的包开发工作流程中。
例子
我通过
从我的系统中删除了包rbenchmark
remove.packages("rbenchmark")
然后
创建了一个虚拟包
devtools::create("SOexample", rstudio = FALSE)
并编辑说明以将 rbenchmark
放入导入中,以便 SOexample
依赖于它。我在 R/hello_world.R
中添加了以下代码:
hello_world <- function() print("Hello, world!")
我尝试了 R CMD INSTALL
,但出现了错误
*installing to library ‘/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5’
ERROR: dependency ‘rbenchmark’ is not available for package ‘SOexample’
*removing ‘/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5/SOexample’
但是,如果我尝试 devtools::install()
:
> devtools::install("SOexample/")
Installing SOexample
trying URL 'https://cloud.r-project.org/src/contrib/rbenchmark_1.0.0.tar.gz'
Content type 'application/x-gzip' length 5093 bytes
==================================================
downloaded 5093 bytes
Installing rbenchmark
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet \
CMD INSTALL '/tmp/RtmpA0NOMe/devtools723832018149/rbenchmark' \
--library='/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5' --install-tests
* installing *source* package ‘rbenchmark’ ...
** package ‘rbenchmark’ successfully unpacked and MD5 sums checked
** R
** demo
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (rbenchmark)
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet \
CMD INSTALL '/home/duckmayr/SOexample' \
--library='/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5' --install-tests
* installing *source* package ‘SOexample’ ...
** R
** byte-compile and prepare package for lazy loading
** help
No man pages found in package ‘SOexample’
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (SOexample)
我正在重建一个自定义 R 程序包,它在 DESCRIPTION 文件的 Depends 行中包含其他库中的 RcppArmadillo。
我是 运行 R 3.5.1。当我在 RStudio 中重建包时,出现错误:
ERROR: dependency ‘RcppArmadillo’ is not available for package 'custom package name'
根据 R Packages book,重建包时必须安装 Depends/Imports 下的包。
解决方案
改用devtools::install()
。
说明
根据 RStudio website,
The Build and Reload command performs several steps in sequence to ensure a clean and correct result:
1.Unloads any existing version of the package (including shared libraries ifnecessary).
2.Builds and installs the package using R CMD INSTALL.
3.Restarts the underlying R session to ensure a clean environment for re-loading the package.
4.Reloads the package in the new R session by executing the library function.
虽然 devtools::install()
将为您安装依赖项 -- 来自 help("install.packages")
:
Uses R CMD INSTALL to install the package. Will also try to install dependencies of the package from CRAN, if they're not already installed.
(强调)单独 R CMD INSTALL
不是这种情况(请参阅 R 中的 ?INSTALL
或命令行中的 R CMD INSTALL --help
等 - 没有提及安装所需的依赖项)。
于是,出现了语言
In fact, any time your package is installed, those packages will, if not already present, be installed on your computer (devtools::load_all() also checks that the packages are installed).
来自 Hadley 的 R Packages is a little specific; it does not pertain to using R CMD INSTALL
(which RStudio's build function apparently uses), but does work for devtools::install()
. It's a matter of personal taste, but honestly I highly recommend using devtools
在您的包开发工作流程中。
例子
我通过
从我的系统中删除了包rbenchmark
remove.packages("rbenchmark")
然后
创建了一个虚拟包devtools::create("SOexample", rstudio = FALSE)
并编辑说明以将 rbenchmark
放入导入中,以便 SOexample
依赖于它。我在 R/hello_world.R
中添加了以下代码:
hello_world <- function() print("Hello, world!")
我尝试了 R CMD INSTALL
,但出现了错误
*installing to library ‘/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5’
ERROR: dependency ‘rbenchmark’ is not available for package ‘SOexample’
*removing ‘/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5/SOexample’
但是,如果我尝试 devtools::install()
:
> devtools::install("SOexample/")
Installing SOexample
trying URL 'https://cloud.r-project.org/src/contrib/rbenchmark_1.0.0.tar.gz'
Content type 'application/x-gzip' length 5093 bytes
==================================================
downloaded 5093 bytes
Installing rbenchmark
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet \
CMD INSTALL '/tmp/RtmpA0NOMe/devtools723832018149/rbenchmark' \
--library='/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5' --install-tests
* installing *source* package ‘rbenchmark’ ...
** package ‘rbenchmark’ successfully unpacked and MD5 sums checked
** R
** demo
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (rbenchmark)
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet \
CMD INSTALL '/home/duckmayr/SOexample' \
--library='/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5' --install-tests
* installing *source* package ‘SOexample’ ...
** R
** byte-compile and prepare package for lazy loading
** help
No man pages found in package ‘SOexample’
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (SOexample)