Search code examples
rdplyrtidyverserlanglintr

Lintr - is there a way to suppress capitalised data frame column name warnings?


I've been writing an R package and using lintr to tidy it up stylistically.

One problem I am seeing a lot is that my data.frame columns are named from the CSV and are capitalised, e.g. MyVariableName. This is outside my control and outputted data will need to follow the same style. Therefore I don't want to rename them on import as it will lead to confusion when following the code from inputted data.

I'm using the tidyverse and NSE. I also tend to use lots of quasi quotation stuff in the code (where I'm building up analysis from quoted building blocks, ie. defining lists containing:

rlang::quo(MyFirstVar + MySecondVar) 

I've tried using .data$ to scope them but still get the warnings for that:

rlang::quo(.data$MyFirstVar + .data$MySecondVar) 

I've found for dplyr select commands you can quote the column names as strings - so that solves some of the warnings.

Is there a way to suppress warnings about data frame column names?


Solution

  • Hmm - by accident I appear to have solved my own answer.

    Instead of using:

    rlang::quo(.data$MyFirstVar + .data$MySecondVar)
    

    You can use:

    rlang::quo(.data[["MyFirstVar"]] + .data[["MySecondVar"]])
    

    (and of course doing that you can also replace the string with a variable if your column name is unknown...)