How to set tab size equivalent of 4 spaces in .lintr configuration file?

383 Views Asked by At

I use ESS in Emacs for R development. No matter for what programming language (R, Rust, Python, etc.) I always set 4 spaces as a tab via a general setting in my Emacs init file :

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)

Recently I had to upgrade to a new Emacs version and I reinstalled everything. Apparently in the latest version of lintr package, there is a control to check wether tabs are two spaces. Given that my Emacs init configuration inserts 4 spaces for tabs, I get loads of warning messages in my R programs:

[indentation lintr] : Indentation should be 2 spaces but is 4 spaces.

I was reading "Using lintr". It seems that by adding a hidden file named .lintr in my HOME directory I might be able to change the default settings and set tabs as 4 spaces. However I didn't find the specific variable in the documentation to achieve this and don't really understand what I should put in that file (both variable and syntax I mean)

I appreciate if you could kindly make some clarification.

1

There are 1 best solutions below

0
Louis Le Nézet On

To configure the .lintr file for indentations with 4 spaces, you can add the following in it:

linters: linters_with_defaults(
    indentation_linter(indent = 4L))

Do not forget the new empty line at the end of the file.

To be sure that the file is correctly set up you can use:

read.dcf(".lintr") # Should give no error

If the file is not available in the workspace you can add it with:

options(lintr.linter_file="Path/to/file/.lintr")

You can also add this line in your .Rprofile to not have to run it everytime.