I created an R package and submitted it to CRAN. The CMD check output 1 NOTE:
fun: no visible binding for global variable 'id'
CRAN suggested that I fix it.
fun() (one of my functions) is a custom import to read files created by another software. These files are very large datasets. Therefore, since I'm optimizing the import, I use data.table and set key, which not only help performance, but are required to run subsequent functions, such as foverlaps().
I'm using:
data.table::setDT(dataImport)
data.table::setkey(dataImport, id)
Why does setkey() creates this note?
How can I set key without creating a note?
The following QA (What is the purpose of setting a key in data.table?) is very useful to understanding setkey(), but neither this nor data.table documentation seem to provide any cues (that I spotted) for the arising of this particular issue. Thank you
Update -Below if the gist of the function where I'm facing this issue.
readoqcsv <- function(x) {
dataImport <- utils::read.table(file = x,
header = TRUE,
sep = "," ,
dec = "." ,
colClasses = c("character",
"integer",
"character",
"character",
"integer",
"NULL",
"NULL",
"NULL",
"integer",
"NULL",
"NULL",
"NULL",
"NULL",
"factor",
"NULL",
"NULL",
"NULL",
"NULL",
"NULL"),
comment.char = "")
data.table::setDT(dataImport)
dataImport$timeStampO <- strptime(dataImport$timeStampO, "%m/%d/%y %H:%M")
dataImport$session_started <- strptime(dataImport$session_started,"%m/%d/%y %H:%M")
dataImport$session_finished <- strptime(dataImport$session_finished,"%m/%d/%y %H:%M")
dataImport$id <- c(1:nrow(dataImport))
Below is the line that (if run) causes the NOTE:
# data.table::setkey(dataImport, id)
return(dataImport)
}