2015-10-19 30 views
4

這可能是一個問題,但我不認爲我已經在Rstudio(0.99.486)中正確設置了lintr。我在「首選項」>「代碼」>「診斷」中具有所有選項,並且已在項目的工作區中加載了lintr。但是,當我運行診斷程序時,我在語法,賦值等方面沒有收到錯誤。有什麼我需要做以啓用所有默認的linters?在R中使用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 
+0

是的,謝謝。我提供的示例代碼在那裏觸發了linting錯誤。 – mattpolicastro

回答

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. 
+0

我對這種困惑表示歉意 - 我試圖理解Rstudio自己的'lintr'集成。在文件上運行'lint()'表現得非常好,只是Rstudio沒有在自己的診斷中顯示全套警告。那麼我錯誤地認爲Rstudio會將所有'lintr'警告顯示爲診斷的一部分,還是需要明確調用'lintr'? – mattpolicastro

+0

聽起來像是RStudio論壇參與者的問題。 –

1

我覺得RStudio診斷與lintr無關。

運行 lint("your-file-to-test.R") (或其他棉絨)從控制檯。

這會將文件加載到RStudio的源面板中(如果它尚未存在),運行測試並在控制檯窗格中打開一個新標籤「標記」,並顯示與您的文件有關的所有警告。

現在,您可以非常輕鬆地處理代碼,因爲兩個窗格都同時顯示相關信息。對於新的檢查,您必須從控制檯重複該命令。 (至少我沒有找到一個更方便的循環校正,測試,糾正方式。)