我编写了一个使用rstudioapi::viewer()函数的R包。显然,并不是每个人都使用RStudio。我现在正在循环运行,试图正确地配置NAMESPACE和DESCRIPTION。
为了不强迫用户安装他们不需要的包(和/或在他们的系统上是无用的),我尝试将rstudioapi放在Suggests部分,并根据其可用性将其称为条件:
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'所以我要么收到不声明它的警告,要么收到声明它的错误。如果你不这样做,那就更糟了,更糟的是你做了一些事情。任何帮助都很感激。
发布于 2017-04-10 11:17:35
我想到的另一个选项是,在您的rstudioapi文件中任何地方都不要列出DESCRIPTION。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上所有内容的系统上,这可能需要更长的时间。
发布于 2017-04-10 07:37:59
我弄明白了为什么我会有那些警告/错误。当我将rstudioapi添加到Suggests:列表时,无意中创建了第二个Suggests:列表。只有第二个被考虑在内(是的,现有的一个是在描述文件的底部,我完全错过了。我不会抹去这个以防发生在别人身上..。
发布于 2017-04-10 01:32:22
我有几个可能有用的主意。
不妨参考一下哈德利·韦翰的在线R包书:http://r-pkgs.had.co.nz/description.html。我从他的书中学到了大部分关于包裹的知识。
我认为您可以将“建议”字段中的包rstudioapi添加到您的描述文件中,其代码如下:
devtools::use_package("rstudioapi", "Suggests")我一直使用Roxygen2包(以及最近的devtools)与命名空间文件交互,所以我不手动编辑命名空间。
下面是我的描述文件的样子:
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检查stack3_0.1.0.tar.gz时,我看到没有错误,只有一个警告。警告是由于默认情况下在说明文件中的License:之后出现的文本造成的。
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.我希望我理解你的问题,这个答复是有帮助的。
https://stackoverflow.com/questions/43312618
复制相似问题