[英]How to not run an example using roxygen2?
I'm writing a geocoding function right now that relies on having a Bing Maps Key. 我现在正在编写一个地理编码功能 ,它依赖于拥有Bing地图密钥。 Obviously I'd rather not publish mine, and the examples fail without one.
显然我宁愿不发布我的,并且没有一个例子就失败了。
How do I include an example for users to run manually, but not have it executed during R CMD check
? 如何为用户手动运行包含示例,但在
R CMD check
期间没有执行?
Use \\dontrun{}
使用
\\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)
#'}
You can use \\donttest{}
to your example. 你可以使用
\\donttest{}
来举例说明。 The snippet will be provided in your documentation, but won't get tested with the R CMD Check. 该片段将在您的文档中提供,但不会通过R CMD Check进行测试。
For more info --> ?example
有关详细信息 - >
?example
#' @example
\donttest{
2^2
}
This 2^2 won't get run when you run devtools::check()
当你运行
devtools::check()
时,这个2 ^ 2将无法运行
Do check it yourself before judging. 在判断之前先自己检查一下。 :)
:)
For those who are using @example path/to/example.R
instead of the @examples
tag you can use the \\dontrun
environment directly in the example.R
file. 对于那些使用
@example path/to/example.R
而不是@examples
标记的用户,可以直接在example.R
文件中使用\\dontrun
环境。 For example 例如
# 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
Ari, I also use roxygen2 (version 4.1.0). 阿里,我也使用roxygen2(版本4.1.0)。 The following is the end of my roxygen2 mark-up in my function (gctemplate) definition till the beginning of the real part.
以下是我的函数(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){
...
I know GSee's dontrun method. 我知道GSee的dontrun方法。
In my technique, the numerical example and the text explaining the numerical example are both comments. 在我的技术中,数值示例和解释数字示例的文本都是注释。 I use indentation to make difference between these two;
我用缩进来区分这两者; Notice there are 1 sharp and 2 sharps respectively after "#'".
请注意,“#”后分别有1个锐利和2个锐利。 I always use the above "#' ## / #' #" technique in my packages.
我总是在我的包中使用上面的“#”## /#'#“技术。 The user is left to copy-paste operation whenever s/he wanna test the function.
每当他/她想测试该功能时,用户就可以进行复制粘贴操作。 This technique is - according to me - more parallel with the classical comment bombardment of the software coding philosophy.
根据我的说法,这种技术与软件编码哲学的经典评论轰炸更为平行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.