jpg*_*ard 5 r devtools package knitr
我目前正在构建一个 R 包,称之为mypackage. 我使用 生成了一个包小插图devtools::use_vignette("my-vignette"),并用内容填充了我的小插图。当然,因为是包小插曲,所以我需要演示一下这个包本身包含的函数和数据的使用。但是,在编织小插图时,我在加载包裹及其内容时遇到了问题。
即使在重新启动 R 并清除工作区之后,小插图中的所有代码块也可以在我的本地计算机上正常运行。但是,当我尝试使用 devtools::build() 构建包时,构建失败:
Error in library(mypackage): there is no package called `mypackage` Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> library Execution halted
控制台中的完整输出devtools::build()是:
* checking for file ‘/path/to/mypackage/DESCRIPTION’ ... OK
* preparing ‘mypackage’:
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
* creating vignettes ... ERROR
Quitting from lines 39-44 (my-vignette.Rmd)
Error: processing vignette 'my-vignette.Rmd' failed with diagnostics:
'my_function' is not an exported object from 'namespace:mypackage'
Execution halted
Run Code Online (Sandbox Code Playgroud)
devtools::document() 运行没有错误,但 devtools::build_vignettes() 显然遇到了一个不同的错误,它不能使用特定的函数(但似乎能够加载包本身):
> devtools::build_vignettes()
Building mypackage vignettes
Moving basic-mypackage-vignette.html, basic-mypackage-vignette.R to inst/doc/
Copying basic-mypackage-vignette.Rmd to inst/doc/
> devtools::build()
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet CMD build \
'/path/to/mypackage' --no-resave-data --no-manual
* checking for file ‘/path/to/mypackage/DESCRIPTION’ ... OK
* preparing ‘auctestr’:
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
* creating vignettes ... ERROR
Quitting from lines 39-44 (my-vignette.Rmd)
Error: processing vignette 'my-vignette.Rmd' failed with
diagnostics:
could not find function "my_function"
Execution halted
Error: Command failed (1)
> devtools::document()
Updating mypackage documentation
Loading mypackage
Run Code Online (Sandbox Code Playgroud)
我认为这是因为包本身不存在于我的 R 库中;我只是使用加载该包devtools::load_all()在进行开发时。我怎样才能解决这个问题并加载我的包以便在包小插图中使用它的功能和数据?具体来说,我如何使包的功能可用于 knitr 用于编织小插图的任何环境?
我已经看到其他包小插图直接使用加载包library()没有问题;例如,在stringr小插图中。
我希望读者可以在没有完全可复制的示例的情况下对此进行评估;复制整个示例很困难,因为它需要一个完整的 R 包目录结构,在此处难以复制或共享。
我确实将我的包直接加载到我的小插图中 ( library(my_package))。
但考虑到你的错误,这可能不是问题......
您能确保my_function确实已导出吗?您应该将以下代码添加到函数文档的末尾。
#' @export
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1316 次 |
| 最近记录: |