Hi,
I am using lintr to lint R files. However, the .lintr file, which is in the same directory is not read, so I can't set any configuration settings. How do I set configuration settings for lintr?
Thanks.
I'm not familiar with how lintr is supposed to read .lintr files. Is there a command line argument which can be used for specifying the file to load?
When you run .lintr in Rstudio or from the console, it will read the file from the working directory.
Here's my workaround. I made a clone of your repo and modified the lint function, so I could pass parameters to it:
function! ale_linters#r#lintr#GetCommand(buffer) abort
return ale#path#BufferCdString(a:buffer)
\ . 'Rscript -e ' . ale#Escape('lintr::lint(commandArgs(TRUE), lintr::with_defaults(line_length_linter = lintr::line_length_linter(120), assignment_linter = NULL))') . ' %t'
endfunction
A better solution would be to create a variable you could set in .vimrc, where you could put the R variables lintr::with_defaults(line_length_linter = lintr::line_length_linter(120), assignment_linter = NULL)).
If you like this solution I can put in a PR in the next few days.
Okay then, that shouldn't be hard to fix. If the the linter has to be run from the directory containing the .lintr file, we should use the function for finding files to find a directory containing the file, and use the function you used before for changing directory. This is also easy to cover with Vader tests.
Then we could consider other options for configuring things.
@ilyakopy @w0rp
Would love to see that feature being added.
I work in projects with different style guides that make a global setting of g:ale_r_lintr_options not very practical.
Your last comment sounds like that implementing this would not be much of a hassle?
Most helpful comment
When you run .lintr in Rstudio or from the console, it will read the file from the working directory.
Here's my workaround. I made a clone of your repo and modified the lint function, so I could pass parameters to it:
function! ale_linters#r#lintr#GetCommand(buffer) abort return ale#path#BufferCdString(a:buffer) \ . 'Rscript -e ' . ale#Escape('lintr::lint(commandArgs(TRUE), lintr::with_defaults(line_length_linter = lintr::line_length_linter(120), assignment_linter = NULL))') . ' %t' endfunctionA better solution would be to create a variable you could set in .vimrc, where you could put the R variables
lintr::with_defaults(line_length_linter = lintr::line_length_linter(120), assignment_linter = NULL)).If you like this solution I can put in a PR in the next few days.