我肯定这是我的误会,因为我不是一个真正的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:警告:全局变量‘隐蔽’没有可见的绑定“
实际上,这不是关于一门课的,因为这也是抱怨:
#! /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:警告:“隐形”没有可见的全局函数定义。
为什么?Short做一些像# nolint start/# nolint end这样的钝工具,我能做些什么来满足lintr?
谢谢!
发布于 2018-07-25 06:18:30
我刚从lintr开始,也遇到了同样的问题。好像是个虫子。
https://github.com/REditorSupport/atom-ide-r/issues/7与实际问题https://github.com/jimhester/lintr/issues/27
目前唯一的解决办法(除了修复lintr中的错误)是禁用对象链接器(这并不是理想的,因为它不会捕获此表单的真正错误)。例如:
with_defaults(object_usage_linter=NULL)(据我所知,对象用法链接器不是用于脚本,而是用于包--据我所知,它的工作将验证整个脚本(!)查看定义了什么全局值。对于R文件都是函数定义的包,这很好,但是对于一个脚本,您并不想每次链接该文件时都运行整个脚本)
发布于 2022-08-22 18:30:47
在lintr函数中使用lintr参数:
lint("myfile.R", linters = linters_with_defaults(
object_length_linter = NULL,
object_name_linter = NULL,
object_usage_linter = NULL))https://stackoverflow.com/questions/51237029
复制相似问题