[R] R CMD check says no visible binding for global variable
Naresh Gurbuxani
n@re@h_gurbux@n| @end|ng |rom hotm@||@com
Tue Jan 28 19:55:56 CET 2025
Data.frame is returned by SQL query. It does have column names. In the function, I make small changes to some columns.
Something like:
Myquery <- “SELECT date, price, stock FROM stocktab WHERE stock = ‘ABC’ AND date > ‘2025-01-01’;”
Prices <- dbGetQuery(con, myquery)
SetDT(Prices)
Prices[, date = as.Date(date)]
R CMD check say “no visible binding for global variable ‘date’”
Sent from my iPhone
On Jan 28, 2025, at 1:24 AM, Sorkin, John <jsorkin using som.umaryland.edu> wrote:
There you go, once again helping strengthen ;)
John
Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: R-help <r-help-bounces using r-project.org> on behalf of avi.e.gross using gmail.com <avi.e.gross using gmail.com>
Sent: Tuesday, January 28, 2025 12:01:25 AM
To: 'Naresh Gurbuxani' <naresh_gurbuxani using hotmail.com>; r-help using r-project.org <r-help using r-project.org>
Subject: Re: [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")
> mydata
first 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))
> mydata
temp1 temp2 temp3
1 1 2 3
-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Naresh Gurbuxani
Sent: Monday, January 27, 2025 5:46 PM
To: r-help using 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 using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7CJSorkin%40som.umaryland.edu%7C25e7bd61380147526b8108dd3f58dced%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638736373101270089%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ExT4UObp9q1CqqqUNyr9GdX3fs6UFoCIndD0UFdQ2bE%3D&reserved=0<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C02%7CJSorkin%40som.umaryland.edu%7C25e7bd61380147526b8108dd3f58dced%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638736373101299265%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=KHzs8stxNBdUeRR9LW8DdYICbzLU3wovaKNJBqL%2BBOY%3D&reserved=0<https://www.r-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7CJSorkin%40som.umaryland.edu%7C25e7bd61380147526b8108dd3f58dced%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638736373101312257%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ygouzLUqvgdAsZjnGVrFwzM93bYn%2Fbjevj5MyagGE04%3D&reserved=0<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C02%7CJSorkin%40som.umaryland.edu%7C25e7bd61380147526b8108dd3f58dced%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638736373101326801%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=kx%2FukXxxEEiVwui%2F6lIsA45q6Hiz97Qpj%2BwHi2eoSqA%3D&reserved=0<https://www.r-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help
mailing list