Naresh Gurbuxani
2025-Jan-27 22:46 UTC
[R] R CMD check says no visible binding for global variable
I have written a function which returns an SQL query result as a data.frame. Each column of data.frame is a variable not explicitly defined. For every column name, R CMD check says ?no visible binding for global variable <name>. Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my iPhone
Ben Bolker
2025-Jan-27 23:04 UTC
[R] R CMD check says no visible binding for global variable
This might be better for r-package-devel at r-project.org (since you're asking a question about package-checking). This is a common problem when using non-standard evaluation. Typically you can either use `utils::globalVariables` or set these variables to NULL near the top of your function. There are arguments for either approach; I'm sure this has been discussed on r-package-devel before but I couldn't quickly locate a thread. On 2025-01-27 5:46 p.m., Naresh Gurbuxani wrote:> I have written a function which returns an SQL query result as a data.frame. Each column of data.frame is a variable not explicitly defined. > > For every column name, R CMD check says ?no visible binding for global variable <name>. Status: 1 NOTE > > Is it possible to tell R CMD check that these variables are OK? > > Thanks, > Naresh > > Sent from my iPhone > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
@vi@e@gross m@iii@g oii gm@ii@com
2025-Jan-28 05:01 UTC
[R] R CMD check says no visible binding for global variable
Naresh, I am not sure how you are creating your data.frame so it has no, I think, column names. There are two scenarios including one where it is not really a valid data.frame and one where it can be handled before any other use as shown below. If it cannot be used, you might need to modify how your SQL or the function you call creates it so it includes either names it chooses or that you supply. One silly solution if to give your data frame names before using it later. In prticulr, if you know what the columns contain, you can choose suitable names like this if you have exactly three columns:> colnames(mydata) <- c("first", "second", "third") > mydatafirst second third 1 1 2 3 If you have a varying number of columns and don't care what the names are, you can make n names that look like temp1, temp2, ... tempn like this:> paste0("temp", 1:ncol(mydata))[1] "temp1" "temp2" "temp3" Obviously, you substitute in whatever your data.frame is called. So the code to add names for columns looks like:> colnames(mydata) <- paste0("temp", 1:ncol(mydata)) > mydatatemp1 temp2 temp3 1 1 2 3 -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Naresh Gurbuxani Sent: Monday, January 27, 2025 5:46 PM To: r-help at r-project.org Subject: [R] R CMD check says no visible binding for global variable I have written a function which returns an SQL query result as a data.frame. Each column of data.frame is a variable not explicitly defined. For every column name, R CMD check says ?no visible binding for global variable <name>. Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my iPhone ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Maybe Matching Threads
- R CMD check says no visible binding for global variable
- R CMD check says no visible binding for global variable
- R CMD check says no visible binding for global variable
- R CMD check says no visible binding for global variable
- R CMD check says no visible binding for global variable