在R

时间:2015-10-19 18:03:55

标签: r

这可能是asinine,但我认为我在Rstudio(0.99.486)中没有正确设置lintr。我在“偏好设置”中有所有选项>代码>诊断并在项目工作区中加载lintr。但是,当我运行诊断程序时,我没有收到语法,赋值等方面的错误。是否需要执行任何操作才能启用所有默认链接?

(请解除我迄今为止所犯的任何愚蠢错误。)

# Sample code; only warnings are for unknown symbol, unexpected
# tokens, and missing whitespace around binary operator
testing = function(test1, test2)
{
  return paste(test, test1)
}
test.var = 1+2

2 个答案:

答案 0 :(得分:1)

我认为RStudio诊断与lintr无关。

运行 lint("your-file-to-test.R") 从控制台(或其他短路)。

这会将文件加载到RStudio的源窗格中(如果它尚未存在),运行测试并在控制台窗格中打开一个新选项卡“Markers”,其中包含有关您文件的所有警告。

现在,您可以轻松处理代码,因为两个窗格同时显示相关信息。对于新检查,您必须从控制台重复该命令。 (至少我没有找到更方便的循环校正,测试,纠正方法。)

答案 1 :(得分:0)

"意想不到的符号"错误是R解释器的语法错误。您应该提供的完整输出提供更多信息:

> lint('test4.r')
test4.r:3:9: style: Use <-, not =, for assignment.
testing = function(test1, test2)
        ^
test4.r:5:10: error: unexpected symbol
  return paste(test, test1)
         ^
test4.r:8:1: style: Trailing blank lines are superfluous.