如何不使用roxygen2运行示例?

如何不使用roxygen2运行示例?,r,roxygen2,R,Roxygen2,我现在正在写一篇关于Bing地图的文章。很明显,我不想发表我的文章,而这些例子没有一个是失败的 如何为用户提供一个手动运行的示例,但在R CMD check期间不执行该示例?使用\dontrun{} #'@examples #'\dontrun{ #'geocode("3817 Spruce St, Philadelphia, PA 19104") #'geocode("Philadelphia, PA") #'dat <- data.frame(value=runif(3),addres

我现在正在写一篇关于Bing地图的文章。很明显,我不想发表我的文章,而这些例子没有一个是失败的


如何为用户提供一个手动运行的示例,但在
R CMD check
期间不执行该示例?

使用
\dontrun{}

#'@examples
#'\dontrun{
#'geocode("3817 Spruce St, Philadelphia, PA 19104")
#'geocode("Philadelphia, PA")
#'dat <- data.frame(value=runif(3),address=c("3817 Spruce St, Philadelphia, PA 19104","Philadelphia, PA","Neverneverland"))
#'geocode(dat)
#'}
#@示例
#“\dontrun{
#“地理编码”(“宾夕法尼亚州费城云杉街3817号,邮编19104”)
#“地理编码”(“宾夕法尼亚州费城”)
#'datAri,我也使用roxygen2(版本4.1.0)。以下是我的函数(gctemplate)定义中roxygen2标记的结束,直到实际零件的开始

#' @examples
#' ## List all G-causalities in a VAR system of 5 variables that will be searched in the pattern of 1 
#' ## causer (like-independent) variable and 2 like-dependents conditional on 5-(1+2)=2 of the remaining 
#' ## variable(s) in the system. Variables are assigned to numbers 1 to nvars. 
#' ## "1 2 5 3 4" in the resulting line of gctemplate is to indicate the 
#' ## (conditonal, partial, etc.) G-causality from variable 1 to variables 2 and 5 
#' ## conditonal on variables 3 and 4.
#' # gctemplate(5,1,2)
#' ## The number of all G-causalities to be searched in the above pattern.
#' #dim(gctemplate(5,1,2))[[1]]
#' @importFrom combinat combn
#' @export
gctemplate <- function(nvars, ncausers, ndependents){
...
#@示例
#“##列出由5个变量组成的VAR系统中的所有G-因果关系,这些变量将以1的模式进行搜索
#“##causer(like独立)变量和2个like依赖项,条件是剩余变量的5-(1+2)=2
#“##系统中的变量。变量被分配给编号1到NVAR。
#gctemplate结果行中的“##”1 2 5 3 4”表示
#“##(条件、部分等)G-变量1到变量2和5的因果关系
#“##变量3和4的条件。
#“#gctemplate(5,1,2)
#“##在上述模式中要搜索的所有G-伤亡人数。
##dim(gctemplate(5,1,2))[[1]]
#“@从combinat combn导入
#“@出口

gctemplate对于使用
@example path/to/example.R
而不是
@examples
标记的用户,可以直接在
example.R
文件中使用
\dontrun
环境。例如

# example.R
\dontrun{
# this is a long running example
for(i in seq(1, 1e5)) { lm(mpg ~ wt, data = mtcars) }
}

# some other shorter example
2 + 2

您可以对示例使用
\donttest{}
。该代码段将在您的文档中提供,但不会使用R CMD检查进行测试

有关详细信息-->
?示例

#' @example
\donttest{
    2^2
    }
当您运行
devtools::check()


判断之前一定要自己检查一下。

这在
?example
和@Jeroen中有记录,我相信
roxygen2
组成了
@example
标签,所以我认为这是
roxygen2
问题。我不认为
\example{}
是有效的——请参见从主题标题判断,问题是关于roxygen2语法,而不是关于.Rd语法?谢谢你的回答。首先它对我不起作用,因为我使用的是
@example
,而不是
@examples
。这两个标记都是在RStudio自动完成中出现的。我现在很高兴。我认为正确的答案是什么sked for is donttest而非dontrun。请参阅?示例和。另请参阅。如果使用
dontrun{}
,则用户可以调用
示例(myFunction,run.dontrun=TRUE)
,而如果您只是注释掉示例,则除了复制/粘贴之外,您没有办法运行示例。这似乎应该是可接受的答案,而不是dontrun。示例“donttest包含通常应该运行的代码,但不是在包检查过程中。”而“dontrun包含不应该运行的代码。”I al所以得到了cran维护人员的评论,从dontrun切换到donttest。完全同意@JulianArls。从cran维护人员那里得到了相同的反馈。这对我不起作用(在Win 10上运行,64位,R版本3.5.0)