簡體   English   中英

如何使用roxygen2運行示例?

[英]How to not run an example using roxygen2?

我現在正在編寫一個地理編碼功能 ,它依賴於擁有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)
#'}

你可以使用\\donttest{}來舉例說明。 該片段將在您的文檔中提供,但不會通過R CMD Check進行測試。

有關詳細信息 - > ?example

#' @example
\donttest{
    2^2
    }

當你運行devtools::check()時,這個2 ^ 2將無法運行

在判斷之前先自己檢查一下。 :)

對於那些使用@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

阿里,我也使用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){
...

我知道GSee的dontrun方法。
在我的技術中,數值示例和解釋數字示例的文本都是注釋。 我用縮進來區分這兩者; 請注意,“#”后分別有1個銳利和2個銳利。 我總是在我的包中使用上面的“#”## /#'#“技術。 每當他/她想測試該功能時,用戶就可以進行復制粘貼操作。 根據我的說法,這種技術與軟件編碼哲學的經典評論轟炸更為平行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM