简体   繁体   English

使用devtools :: document构建R包错误

[英]Building an R package error with devtools::document

I am building R packages using devtools. 我正在使用devtools构建R包。 I've built a package with some functions that I'd like to include. 我构建了一个包含一些我想包含的功能的软件包。 And I'd like to load the package and its documentation at startup. 而且我想在启动时加载程序包及其文档。 My package files are located at the location: 我的软件包文件位于以下位置:

'~/global/Rcode/Startup Package'

My .Rprofile file looks like this: 我的.Rprofile文件如下所示:

.First <- function(){
    library(devtools)
    location <- '~/global/Rcode/Startup Package'
    document(location)
}

However when I open R, the functions from the package are loaded but the documentation is not. 但是,当我打开R时,将加载程序包中的函数,但不会加载文档。

If I run the same lines of code after startup myself, namely: 如果我自己启动后运行相同的代码行,即:

library(devtools)
location <- '~/global/Rcode/Startup Package'
document(location)

then everything works and the package correctly documents. 然后一切正常,包装正确记录。 This thus seems like a rather weird bug! 因此,这似乎是一个相当奇怪的错误!

(As a partial fix I can run (作为部分修复,我可以运行

install(location) 

and treat it like a normal r package and everything works fine, however this takes time and as I intend to update the package a lot and do not really want to have to run this every time, especially as the devtools option should work.) 并像对待普通r包一样对待它,一切正常,但是这需要时间,并且由于我打算大量更新该包,因此并不想每次都运行它,特别是因为devtools选项应该可以运行。)

Make sure utils is loaded before loading devtools otherwise there's no help function for devtools to overwrite. 确保在加载devtools之前先加载utils否则devtools不会覆盖help功能。

With .Rprofile: 使用.Rprofile:

.First = function(){
library(utils)
library(devtools)
document("./foo")
}

then R startup goes: 然后R启动去:

[stuff]
Type 'q()' to quit R.

Updating foo documentation
Loading foo

And help is devtools version: 并且helpdevtools版本:

> environment(help)
<environment: namespace:devtools>

Remove that library(utils) and you'll see the help function is the one in utils that won't find your package documentation. 删除该library(utils) ,您将看到help函数是utils中找不到您的软件包文档的函数。

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

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