Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using data.table in a package, R CMD check NOTEs: no visible global function definition for '.'

Tags:

r

data.table

I have tried (via roxygen2) @import data.table and importing just the functions I use (@importFrom data.table data.table rbindlist setkey setDT := .SD. Either way I get this warning about the . "function", which I assume is from this kind of usage: dt[x, .(a, b, c)]. I can't find any way to import . without causing an error.

And as a followup question, is there a recommended way to hide the no visible binding for global variable for a, b, and c? There are quite a few other questions about this latter NOTE but I haven't seen a satisfying answer. globalVariable and setting the column names to placeholder values elsewhere in the function are ugly hacks. Should I switch to some other method of specifying the columns which would solve both issues?

like image 601
Matt Chambers Avatar asked Apr 27 '17 15:04

Matt Chambers


Video Answer


1 Answers

Instead of using globalVariables you can also define those variables locally, not polluting global environment.
I will copy my comment from github issue Rdatatable/data.table#850

you can just assign NULL to the variable before using it (not confuse with override it). So you are not defining global variables, but just defining them locally in a function where you are using them.

Worth to note that issue is relevant to any NSE interface, not just data.table. NSE basically makes CRAN check unable to investigate if variables used has been defined in some NSE interface, thus raising a note.

like image 148
jangorecki Avatar answered Oct 02 '22 15:10

jangorecki