我有一个用R6class构建的函数,我想知道传递devtools::check()的最好方法是。目前,这个repex给出了注释
> checking R code for possible problems ... NOTE
obj_gen : <anonymous>: no visible binding for global variable ‘self’
Undefined global functions or variables:
self但是,它只在实际调用self时给出注释。例如,在打印函数中,而不是在初始化内部的赋值中。
在Tidyverse (here)中,使用了importFrom R6 R6Class。但是,在本例中,在打印函数中调用self似乎会触发全局变量注释。
Repex
#' func
#' @param ... opts
#' @examples
#'\dontrun{
#' obj_gen(bar = "fubar")
#'}
obj_gen <- function(...){
#' @importFrom R6 R6Class
obj <- R6::R6Class("my_class",
public = list(
foo = NULL,
initialize = function(bar = NA){
self$foo <- bar
},
print = function(){
cat("Anyone for ",
self$foo,
"?",
sep = "")
}
)
)
obj$new(...)
}一位大学生非常有帮助地建议将它添加到我正在考虑的globalVariables(info)中。但是,我想知道是否有更好的方法来处理它,使用文档:)
我的Roxygen版本是7.1.1。
发布于 2021-06-09 02:12:40
具有虚拟self <- NA定义的解决方案。
#' func
#' @param ... opts
#' @import R6
#' @examples
#'\dontrun{
#' obj_gen(bar = "fubar")
#'}
obj_gen <- function(...){
self <- NA
obj <- R6Class("my_class",
public = list(
foo = NULL,
initialize = function(bar = NA) {
self$foo <- bar
},
print = function() {
cat("Anyone for ",
self$foo,
"?",
sep = "")
}
)
)
obj$new(...)
}https://stackoverflow.com/questions/67584669
复制相似问题