【发布时间】:2018-07-09 00:41:26
【问题描述】:
我确定这是我的误解,因为我不是真正的 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: 警告:‘cloaked’没有可见的全局函数定义
为什么? 短做一些像# nolint start/# nolint end这样的钝器,我能做些什么来满足lintr?
谢谢!
【问题讨论】:
-
嗨@Hack-R 谢谢!但是,同样的问题,似乎......(我的意思是,代码仍然有效......无论我把你的线路放在哪里,我都会得到相同的 lintr 错误......在库之前,在库之后,在主函数内部,之后main 的定义和对 main 本身的调用之后......)
-
嗨。我刚刚尝试在此代码上运行 lintr v2,并且不再引发对象使用问题(尽管我可以在同一文件中使用
y <- function() {print(x)}获得对象使用问题)。所以这看起来像是一个已解决的问题