我有一个我在RStudio中构建的R包,我们称之为my_pkg
。当我在RStudio中运行devtools::load_all(".")
时(特别是使用Ctrl + Shift + L
快捷方式),我收到以下消息:
Loading my_pkg
Warning messages:
1: character(0)
2: character(0)
3: character(0)
4: character(0)
5: character(0)
包中的所有功能都可以正常工作。我的NAMESPACE
和DESCRIPTION
文件已完整,没有语法错误。但是,当我运行?my_pkg
时,帮助文件与DESCRIPTION
文件中提供的规范不匹配。当我从Imports
中删除DESCRIPTION
时,不再有character(0)
警告消息。当然,我需要那些进口。当我将Imports
更改为Suggests
时,会出现character(0)
警告消息。
以下是描述文件内容,更改了一些内容以保护IP。
Package: scoutdroid
Title: This is where the title is.
Version: 0.1
Authors@R: "Ben Hanowell <benjamin.hanowell@redfin.com> [aut, cre]"
Description: This is where the description is.
Depends:
R (>= 3.1.0)
Imports:
dplyr,
lubridate,
mboost,
randomForestSRC,
RODBC,
stringr
License: file LICENSE
LazyData: true
这是NAMESPACE
。
# Generated by roxygen2 (4.0.1): do not edit by hand
import(RODBC)
import(dplyr)
import(lubridate)
import(mboost)
import(parallel)
import(randomForestSRC)
import(stringr)
当我使用RStudio Build&amp;在Build选项卡中重新加载按钮,我收到以下警告:
**准备延迟加载包
Warning: replacing previous import by 'lubridate::intersect' when loading 'scoutdroid'
Warning: replacing previous import by 'lubridate::setdiff' when loading 'scoutdroid'
Warning: replacing previous import by 'lubridate::union' when loading 'scoutdroid'
编辑添加了更多详细信息,以帮助人们了解可能发生的情况。
编辑2 我还添加了DESCRIPTION
文件,但我没有提供完整的软件包,这是专有的。
编辑3 已添加NAMESPACE
。
编辑4 添加了使用RStudio Build&amp; amp; “构建”选项卡中的“重新加载”按钮。
答案 0 :(得分:23)
在评论中进行了一些拨号后,我们发现load_all
给出的空警告实际上是在加载软件包时由于函数名冲突而启动的。
问题是您从包中导入函数,然后覆盖该函数。当发生这种情况时,当你在RStudio中点击“Build&amp; Reload”时,R会抛出警告:
Warning: replacing previous import by 'lubridate::intersect' when loading 'scoutdroid'
Warning: replacing previous import by 'lubridate::setdiff' when loading 'scoutdroid'
Warning: replacing previous import by 'lubridate::union' when loading 'scoutdroid'
看起来load_all
可能试图消除这些警告(只是一个猜测),这就是为什么你看到character(0)
而不是实际的警告。 (这些特别的警告很难沉默。)
导入整个包的命名空间通常不是一个好主意。您应该只导入您需要的符号。请参阅我的this post了解更多信息。
解决方案是在您的NAMESPACE文件中使用importFrom
而不是import
。
答案 1 :(得分:2)
这也可能是由于roxygen2
文档中的链接断开所致。例如,当您使用错误的名称链接到包外部的函数时,请说\link[stringi]{STRI_C}
而不是\link[stringi]{stri_c}