OCHA-DAP / hdx-signals

HDX Signals
https://un-ocha-centre-for-humanitarian.gitbook.io/hdx-signals/
GNU General Public License v3.0
5 stars 0 forks source link

lintr vs Rstudio default 4 spaces after function vs 2 #85

Closed zackarno closed 4 months ago

zackarno commented 4 months ago

lintr thinks there should only be 2 spaces when defining custom function arguments where as Rstudio is set by default to do 4. Kind of annoying -- should we adjust lintr or Rstudio?

caldwellst commented 4 months ago

So, I thought so as well. Turns out, the tidyverse style guide is that the closing ) and starting { for functions must go on the last line of the function call. The {lintr} error wasn't clear, but it's because it's not expecting double indents ever except in the case of a multi-line function call, which it only recognises if you follow the above.

So, this is valid:

function(
    a,
    b) {
  ...
}

This is not:

function(
    a,
    b
) {
  ...
}
zackarno commented 4 months ago

gross 🤣 ... okay good to know, i'll fix it

zackarno commented 4 months ago

Something else that seems weird is the lintr error from:

This will say something like "Hanging indent should be 36 spaces but is 4 spaces"

  gdf_sample_pts <- my_func(
    x ,
    y,
    z)

Where as, this will create no error

my_func(x,
        y,
        z)

The only way I see to get Rstudio to do this type of indenting is to leave x on the first line...which i thought you had said it should always be dropped down. If you drop it down it goes to 4 spaces and command+i won't save you

caldwellst commented 4 months ago

This should not generate an error if double indented:

gdf_sample_pts <- my_func(
    x,
    y,
    z) {
}

The expectation is that either you place the first argument double indented, or on the same level as my_func(. I never liked that method and didn't know it was in the style guide til the other day! I have been following most of the style guide but not so certain about the function stylings ha.