使用建议包时配置NAMESPACE和说明
我写了一个使用rstudioapi::viewer()
函数的R包。 显然,并不是每个人都使用RStudio。 我现在正在试着正确配置NAMESPACE
和DESCRIPTION
。
为了不强制用户安装他们不需要的软件包(和/或在他们的系统上无用),我尝试将rstudioapi
放入Suggests
部分,并将其rstudioapi
可用条件:
if(.Platform$GUI == "RStudio") {
if ("rstudioapi" %in% rownames(installed.packages())) {
rstudioapi::viewer(outfile_path)
} else {
message("To view html content in RStudio, run install.packages('rstudioapi').")
message("Switching method to 'browser'")
method <- "browser"
}
但在R CMD CHECK
,我得到:
checking dependencies in R code ... WARNING
'::' or ':::' import not declared from: 'rstudioapi'
所以我去声明它,将importFrom(rstudioapi, viewer)
到我的NAMESPACE
。 结果:
checking package dependencies ... ERROR
Namespace dependency not required: 'rstudioapi'
回到官方文档,我也尝试了以下内容:
if (requireNamespace("rstudioapi", quietly = TRUE)) {
rstudioapi::viewer(outfile_path)
} else { ...
无济于事:
checking dependencies in R code ... WARNING
'::' or ':::' import not declared from: 'rstudioapi'
'loadNamespace' or 'requireNamespace' call not declared from: 'rstudioapi'
所以我得到一个警告不宣布它,或者宣布它的错误。 如果你不这样做,那该死的,如果你确实有点儿,那更是该死的。 任何帮助赞赏。
发生在我身上的另一个选择是,不要在您的DESCRIPTION
文件中的任何地方列出rstudioapi
。 RStudio提供了使用查看器的提示,这可能会有所帮助,并且不需要依赖rstudioapi
。
他们的建议是使用
viewer <- getOption("viewer")
if (!is.null(viewer))
viewer("http://localhost:8100")
else
utils::browseURL("http://localhost:8100")
这是有效的,因为在启动时,RStudio会创建一个名为viewer
的选项并使用函数来填充它。 如果您不使用RStudio, getOption("viewer")
将返回NULL
,您可以重定向它以使用系统的默认浏览器。 这基本上是你已经完成的工作,但不需要额外的依赖关系。
这还有一个好处,就是比检查installed.packages
快大约1000倍,但这仍然是以纳秒为单位测量的,所以可能不是一个大问题(需要注意的是,我只安装了192个软件包,可能需要更长的时间下载CRAN上的所有内容)。
我想清楚为什么我有这些警告/错误。 当我将rstudioapi
添加到Suggests:
列表中时,我无意中创建了第二个Suggests:
列表。 只有第二个被考虑到了(是的,现有的是在DESCRIPTION文件的底部,完全是我错过了。我不会擦除这个以防万一它发生在别人身上......
我有一些可能有用的想法。
参考Hadley Wickham的在线R包书籍可能会有所帮助:http://r-pkgs.had.co.nz/description.html。 我从他的书中了解了大部分(我很少)关于软件包的知识。
我认为你可以添加到你的描述文件,在“Suggests”字段下的包装rstudioapi
下面的代码:
devtools::use_package("rstudioapi", "Suggests")
我一直使用Roxygen2
软件包(以及最近的devtools
)与NAMESPACE文件进行交互,所以我不会手动编辑NAMESPACE。
以下是我的DESCRIPTION文件的外观:
Package: stack3
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <yourself@somewhere.net>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
Suggests:
rstudioapi
RoxygenNote: 5.0.1
然后我跑了
devtools::build()
获取stack3_0.1.0.tar.gz文件。 请注意我命名我的包stack3
。 在运行R CMD CHECK stack3_0.1.0.tar.gz时,我看到没有错误和一个警告。 该警告是由于默认情况下的文本遵循许可证:在描述文件中。
R CMD CHECK stack3_0.1.0.tar.gz
* using log directory ‘/Users/frederickboehm/Box Sync/stack3.Rcheck’
* using R version 3.3.3 (2017-03-06)
* using platform: x86_64-apple-darwin13.4.0 (64-bit)
* using session charset: UTF-8
* checking for file ‘stack3/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘stack3’ version ‘0.1.0’
* package encoding: UTF-8
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether package ‘stack3’ can be installed ... OK
* checking installed package size ... OK
* checking package directory ... OK
* checking DESCRIPTION meta-information ... WARNING
Non-standard license specification:
What license is it under?
Standardizable: FALSE
* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking loading without being on the library search path ... OK
* checking examples ... NONE
* checking PDF version of manual ... OK
* DONE
Status: 1 WARNING
See
‘/Users/frederickboehm/Box Sync/stack3.Rcheck/00check.log’ for details.
我希望我能理解你的问题,并且这个回应是有帮助的。
链接地址: http://www.djcxy.com/p/71157.html上一篇: Configuring NAMESPACE and DESCRIPTION when using a Suggested Package
下一篇: gWidgets packaging