2

When running lintr on an R function that uses data.table I get the following warning:

warning: no visible global function definition for '.', Did you mean '-'?  

I thought an easy fix would be adding importFrom data.table .. I also tried quoting the dot with a backtick but it really doesn't seem to be exported. What is the recommened way to get of this error?

I could add the line

`.` <- function(){}

somewhere but I didn't get that to work and it's hacky.

Bob Jansen
  • 1,215
  • 2
  • 12
  • 31
  • 3
    `.` is not a function. data.table [replaces it with `list`](https://github.com/Rdatatable/data.table/blob/master/R/data.table.R#L181) before the expression is evaluated. You can define `. <- list` if you simply want to alias list (but that's slightly less efficient). – Roland Apr 29 '19 at 15:24
  • Thanks for the insight, I see that data.table developers went out of their way to not alias it so I'm reluctant to do that myself now. – Bob Jansen Apr 29 '19 at 15:33
  • 1
    Well, why do you want to import `.`? If you want to use data.table, I would import the whole package. – Roland Apr 29 '19 at 15:34
  • Now that I see that `.` is not even a function I don't want to import `.` it any more. My goal is just to get rid of the lintr warning. – Bob Jansen Apr 29 '19 at 15:35
  • As an even more fun exercise, we also use the `..` syntax to refer to variables like this `dt[, ..var * 2]` or something. For this lintr gives: `warning: no visible binding for global variable ‘..var’, Did you mean 'var'?`. Yes but no. – Bob Jansen Apr 29 '19 at 15:41
  • 1
    I define `. <- NULL` in my package when I use it. This way `.` is define and R CMD check is happy. – JRR Apr 29 '19 at 22:03
  • 1
    That works for `R CMD check` but not for `lintr`. – Bob Jansen Apr 30 '19 at 06:57

1 Answers1

0

What if you try quoting the dot with double quotes? importFrom data.table "."

I know this is how I've done imports for the magrittr pipe operator

If that doesn't work you can always add the . to a globals.R file that defines your global variables using utils::globalVariables()

if(getRversion() >= "2.15.1")  utils::globalVariables(c("."))
Paul Wildenhain
  • 1,321
  • 10
  • 12
  • 3
    There is no `.` function in package data.table. Thus, you cannot import this function from it. – Roland Apr 29 '19 at 15:31
  • Ah, in that case, you can always add the `.` as a global variable to prevent this `devtools::check()` warning – Paul Wildenhain Apr 29 '19 at 15:33
  • This seems to work to shut up `lintr`, thanks. I'll do some further testing, hopefully nothing breaks in subtle ways. – Bob Jansen Apr 29 '19 at 15:38
  • 1
    Ah, I see this was a `lintr` problem, not a `devtools` problem. I just remember dealing with this from the devtools side -- glad this worked for `lintr` as well – Paul Wildenhain Apr 29 '19 at 15:45