我敢肯定这是对我的误解,因为我不是真正的 R 程序员......
我在这里有我的代码:https ://gist.github.com/bnsh/3839c4eb2c6b31e32c39ec312014b2b8
#! /usr/bin/env Rscript
library(R6)
Cloaked <- R6::R6Class("Cloaked",
public = list(
msg = function() {
return(paste(
"this code _works_, but lintr (https://github.com/jimhester/lintr)",
"complains that cloak_class.R:19:8: warning: no visible binding for",
"global variable ‘Cloaked’ when I try to use Cloaked within a",
"function. It's fine tho, if I use it _outside_ a function."
))
}
)
)
main <- function() {
c <- Cloaked$new()
c$msg()
}
main()
它有效......但是,lintr 抱怨:“cloak_class.R:19:8: 警告:全局变量 'Cloaked' 没有可见绑定”
实际上,这与课程无关,真的,因为这也抱怨:
#! /usr/bin/env Rscript
cloaked <- function() {
return(paste(
"this code _works_, but lintr (https://github.com/jimhester/lintr)",
"complains that cloak_function.R:13:3: warning: no visible global",
"function definition for ‘cloaked’ when I try to use cloaked within",
"a function. It's fine tho, if I use it _outside_ a function."
))
}
main <- function() {
cloaked()
}
main()
这段代码也可以运行,但是 lintr 说:cloak_function.R:13:3: warning: no visible global function definition for 'cloaked'</p>
为什么?没有做一些像/这样的钝器,我能做些什么来满足 lintr ?# nolint start
# nolint end
谢谢!