Re: [R] R CMD check says no visible binding for global variable
Hi Naresh Gurbuxani, There are already several answers dealing with the specific code that you wrote, but my reaction is to step back a little. R CMD � starts an R session but takes standard input from a file. (In Unix-like systems you might even be able to make an R script into an executable file.) I think it even uses the same .Rprofile as a regular R session. If there is a problem, you can paste the code a few lines at a time into a new ordinary R session. Then you can also set breakpoints (using debug, trace, or similar) in whatever functions you think caused the problem. You could also wrap all the code in a function and use the debugger to step through that (which may help if the error occurs in an iteration of a loop body). Regards, Jorgen Harmse. Message: 1 Date: Mon, 27 Jan 2025 22:46:21 + From: Naresh Gurbuxani To: "r-help@r-project.org" Subject: [R] R CMD check says no visible binding for global variable Message-ID: Content-Type: text/plain; charset="utf-8" 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 . Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my iPhone [[alternative HTML version deleted]] __ R-help@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.
Re: [R] R CMD check says no visible binding for global variable
While my problem is solved, if not elegantly, data.table is widely used in packages. Any package builders using data.table who have encountered and solved this problem? Sent from my iPhone > On Jan 28, 2025, at 4:52 PM, avi.e.gr...@gmail.com wrote: > > That is an interesting fix Duncan suggested and it sounds now like > everything WORKED as intended in data.table except that any checker being > used externally is not able to del with things that look like a variable but > are actually not a variable currently visible except within a function that > is doing deferred evaluation. In this case, it recognizes the raw unevaluated > string as being the name of a column within the data.table. > > I would guess this can cause similar anomalies in the dplyr package when it > does the same kinds of non-standard evaluation and I wonder even about the > with() command or the within() which internally expand columns out so that > commands using them work. > > But setting the variable to NULL bothers me. Yes, it shuts up a check to see > if the variable exists. But is there any reason you could not have a global > variable and any number of local variables with the same name as the column, > especially if non-standard evaluation only looks for the column and ignores > other instances of the name in other environments? Setting it to NULL > unconditionally could mess up some programs. > > There are ways to set it conditionally and save the previous value and > restore it after but this gets to be lots more work ... > > > -Original Message- > From: R-help On Behalf Of Naresh Gurbuxani > Sent: Tuesday, January 28, 2025 4:25 PM > To: Duncan Murdoch > Cc: r-help@r-project.org > Subject: Re: [R] R CMD check says no visible binding for global variable > > This solution worked. > Thanks > > Sent from my iPhone > >>> On Jan 28, 2025, at 3:09 PM, Duncan Murdoch >>> wrote: >>> >>> On 2025-01-28 1:55 p.m., Naresh Gurbuxani wrote: >>> 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)] >> >> If Prices were a regular dataframe at this point, then the message would be >> correct. You can't calculate `as.Date(date)` without telling R where to look >> for the `date` variable. >> >> However, you have set it to be a data.table instead. They use nonstandard >> evaluation and look up `date` in the columns of `Prices`, and things work. >> However, R's checks don't know this, so you still get the complaint. >> >> The fix given by others is easiest: sometime before this add a line >> >> date <- NULL >> >> and it will satisfy the check code. >> >> Duncan Murdoch >>> 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 >>>> wrote: >>> >>> There you go, once again helping strengthen ;) >>> John >>> Get Outlook for iOS<https://aka.ms/o0ukef> >>> >>> From: R-help on behalf of >>> avi.e.gr...@gmail.com >>> Sent: Tuesday, January 28, 2025 12:01:25 AM >>> To: 'Naresh Gurbuxani' ; r-help@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, >>&g
Re: [R] R CMD check says no visible binding for global variable
On 28.01.2025 22:52, avi.e.gr...@gmail.com wrote: That is an interesting fix Duncan suggested and it sounds now like everything WORKED as intended in data.table except that any checker being used externally is not able to del with things that look like a variable but are actually not a variable currently visible except within a function that is doing deferred evaluation. In this case, it recognizes the raw unevaluated string as being the name of a column within the data.table. I would guess this can cause similar anomalies in the dplyr package when it does the same kinds of non-standard evaluation and I wonder even about the with() command or the within() which internally expand columns out so that commands using them work. The help pages of with() and within() do warn not to use it in package code ... I'd avoid non standard evaluation in any case. Best, Uwe Ligges But setting the variable to NULL bothers me. Yes, it shuts up a check to see if the variable exists. But is there any reason you could not have a global variable and any number of local variables with the same name as the column, especially if non-standard evaluation only looks for the column and ignores other instances of the name in other environments? Setting it to NULL unconditionally could mess up some programs. There are ways to set it conditionally and save the previous value and restore it after but this gets to be lots more work ... -Original Message- From: R-help On Behalf Of Naresh Gurbuxani Sent: Tuesday, January 28, 2025 4:25 PM To: Duncan Murdoch Cc: r-help@r-project.org Subject: Re: [R] R CMD check says no visible binding for global variable This solution worked. Thanks Sent from my iPhone On Jan 28, 2025, at 3:09 PM, Duncan Murdoch wrote: On 2025-01-28 1:55 p.m., Naresh Gurbuxani wrote: 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)] If Prices were a regular dataframe at this point, then the message would be correct. You can't calculate `as.Date(date)` without telling R where to look for the `date` variable. However, you have set it to be a data.table instead. They use nonstandard evaluation and look up `date` in the columns of `Prices`, and things work. However, R's checks don't know this, so you still get the complaint. The fix given by others is easiest: sometime before this add a line date <- NULL and it will satisfy the check code. Duncan Murdoch 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 wrote: There you go, once again helping strengthen ;) John Get Outlook for iOS<https://aka.ms/o0ukef> From: R-help on behalf of avi.e.gr...@gmail.com Sent: Tuesday, January 28, 2025 12:01:25 AM To: 'Naresh Gurbuxani' ; r-help@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 On Behalf Of Naresh Gurbuxani Sent: Monday, January 27, 2025 5:46 PM To: r-help@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 . Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my i
Re: [R] R CMD check says no visible binding for global variable
That is an interesting fix Duncan suggested and it sounds now like everything WORKED as intended in data.table except that any checker being used externally is not able to del with things that look like a variable but are actually not a variable currently visible except within a function that is doing deferred evaluation. In this case, it recognizes the raw unevaluated string as being the name of a column within the data.table. I would guess this can cause similar anomalies in the dplyr package when it does the same kinds of non-standard evaluation and I wonder even about the with() command or the within() which internally expand columns out so that commands using them work. But setting the variable to NULL bothers me. Yes, it shuts up a check to see if the variable exists. But is there any reason you could not have a global variable and any number of local variables with the same name as the column, especially if non-standard evaluation only looks for the column and ignores other instances of the name in other environments? Setting it to NULL unconditionally could mess up some programs. There are ways to set it conditionally and save the previous value and restore it after but this gets to be lots more work ... -Original Message- From: R-help On Behalf Of Naresh Gurbuxani Sent: Tuesday, January 28, 2025 4:25 PM To: Duncan Murdoch Cc: r-help@r-project.org Subject: Re: [R] R CMD check says no visible binding for global variable This solution worked. Thanks Sent from my iPhone > On Jan 28, 2025, at 3:09 PM, Duncan Murdoch wrote: > > On 2025-01-28 1:55 p.m., Naresh Gurbuxani wrote: >> 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)] > > If Prices were a regular dataframe at this point, then the message would be > correct. You can't calculate `as.Date(date)` without telling R where to look > for the `date` variable. > > However, you have set it to be a data.table instead. They use nonstandard > evaluation and look up `date` in the columns of `Prices`, and things work. > However, R's checks don't know this, so you still get the complaint. > > The fix given by others is easiest: sometime before this add a line > > date <- NULL > > and it will satisfy the check code. > > Duncan Murdoch >> 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 wrote: >> >> There you go, once again helping strengthen ;) >> John >> Get Outlook for iOS<https://aka.ms/o0ukef> >> ________________ >> From: R-help on behalf of >> avi.e.gr...@gmail.com >> Sent: Tuesday, January 28, 2025 12:01:25 AM >> To: 'Naresh Gurbuxani' ; r-help@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 On Behalf Of Naresh Gurbuxani >> Sent: Monday, January 27, 2025 5:46 PM >> To: r-help@r-project.org >> Subject: [R] R CMD check says no visible binding
Re: [R] R CMD check says no visible binding for global variable
Naresh, I think your details suggest your earlier request was not well defined. Your problem looks like this line of code was wrong and did something you did not expect. It should be easy to fix. But I note you changed Prices to use the data.table package. Mind you, I thought the function was lower case setDT and you mention SetDT. At this point, I cannot help you as I do not know enough about the package. As a general rule, the best way to ask for help includes mentioning the packages you used. The code snippet did not have a library() statement that would be needed. Here is the original: Prices[, date = as.Date(date)] I cannot speak for how data.table might parse that. In base R, it would not work and I can suggest what would. What you wanted to do was convert a column containing a date in some format into a date in some other format. Am I right? In particular, I am guessing the date returned by SQL into the Prices data.frame is there as text in a standard format. If not, you may need to convert the date some more specific way. Here is a way outside data.table that might work within it as well. Prices$date <- as.Date(Prices$date) The above replaces the contents of one vector/column and note the suggested use is not of “=” which gave you a side-effect, but to use “<-“ in the R-thritic way. There are other variations and yet more if using the dplyr or other packages, but the above is fairly simple and straightforward and uses base R. I will spare you further explanations and lecturing on what I thought your code would do as I looked again and realize it is not a standard data.frame anymore. Here is a test case if your date is in this format: Prices <- data.frame(date=c("2025-01-01", "2025-01-26"), price=c(12, 14), stock=c("AAPL", "MSFT")) Prices$date <- as.Date(Prices$date) The result is: > Prices date price stock 1 2025-01-0112 AAPL 2 2025-01-2614 MSFT If your date is in some other format, you have to specify the format. See the help on as.Date to see how to set the format=option. If anyone wants to explain better on the data.table method and maybe explain what went wrong, I would be happy to hear it, as well as any corrections on what I wrote. From: Naresh Gurbuxani Sent: Tuesday, January 28, 2025 1:56 PM To: John Sorkin Cc: avi.e.gr...@gmail.com; r-help@r-project.org Subject: Re: [R] R CMD check says no visible binding for global variable 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 mailto:jsor...@som.umaryland.edu> > wrote: There you go, once again helping strengthen ;) John Get Outlook for iOS <https://aka.ms/o0ukef> _ From: R-help mailto:r-help-boun...@r-project.org> > on behalf of avi.e.gr...@gmail.com <mailto:avi.e.gr...@gmail.com> mailto:avi.e.gr...@gmail.com> > Sent: Tuesday, January 28, 2025 12:01:25 AM To: 'Naresh Gurbuxani' mailto:naresh_gurbux...@hotmail.com> >; r-help@r-project.org <mailto:r-help@r-project.org> mailto:r-help@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
Re: [R] R CMD check says no visible binding for global variable
This solution worked. Thanks Sent from my iPhone > On Jan 28, 2025, at 3:09 PM, Duncan Murdoch wrote: > > On 2025-01-28 1:55 p.m., Naresh Gurbuxani wrote: >> 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)] > > If Prices were a regular dataframe at this point, then the message would be > correct. You can't calculate `as.Date(date)` without telling R where to look > for the `date` variable. > > However, you have set it to be a data.table instead. They use nonstandard > evaluation and look up `date` in the columns of `Prices`, and things work. > However, R's checks don't know this, so you still get the complaint. > > The fix given by others is easiest: sometime before this add a line > > date <- NULL > > and it will satisfy the check code. > > Duncan Murdoch >> 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 wrote: >> >> There you go, once again helping strengthen ;) >> John >> Get Outlook for iOS<https://aka.ms/o0ukef> >> ________________ >> From: R-help on behalf of >> avi.e.gr...@gmail.com >> Sent: Tuesday, January 28, 2025 12:01:25 AM >> To: 'Naresh Gurbuxani' ; r-help@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 On Behalf Of Naresh Gurbuxani >> Sent: Monday, January 27, 2025 5:46 PM >> To: r-help@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 . Status: 1 NOTE >> Is it possible to tell R CMD check that these variables are OK? >> Thanks, >> Naresh >> Sent from my iPhone >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >> PLEASE do read the posting guide >> https://www.r-project.org/posting-guide.html<https://www.r-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >> PLEASE do read the posting guide >> https://www.r-project.org/posting-guide.html<https://www.r-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >>[[alternative HTML version deleted]] >> __ >> R-help@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. > __ R-help@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.
Re: [R] R CMD check says no visible binding for global variable
On 2025-01-28 1:55 p.m., Naresh Gurbuxani wrote: 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)] If Prices were a regular dataframe at this point, then the message would be correct. You can't calculate `as.Date(date)` without telling R where to look for the `date` variable. However, you have set it to be a data.table instead. They use nonstandard evaluation and look up `date` in the columns of `Prices`, and things work. However, R's checks don't know this, so you still get the complaint. The fix given by others is easiest: sometime before this add a line date <- NULL and it will satisfy the check code. Duncan Murdoch 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 wrote: There you go, once again helping strengthen ;) John Get Outlook for iOS<https://aka.ms/o0ukef> From: R-help on behalf of avi.e.gr...@gmail.com Sent: Tuesday, January 28, 2025 12:01:25 AM To: 'Naresh Gurbuxani' ; r-help@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 On Behalf Of Naresh Gurbuxani Sent: Monday, January 27, 2025 5:46 PM To: r-help@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 . Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my iPhone __ R-help@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@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=ygouzLUqvgdAsZjnGVrFwzM93
Re: [R] R CMD check says no visible binding for global variable
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 wrote: There you go, once again helping strengthen ;) John Get Outlook for iOS<https://aka.ms/o0ukef> From: R-help on behalf of avi.e.gr...@gmail.com Sent: Tuesday, January 28, 2025 12:01:25 AM To: 'Naresh Gurbuxani' ; r-help@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 On Behalf Of Naresh Gurbuxani Sent: Monday, January 27, 2025 5:46 PM To: r-help@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 . Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my iPhone __ R-help@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@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
Re: [R] R CMD check says no visible binding for global variable
There you go, once again helping strengthen ;) John Get Outlook for iOS<https://aka.ms/o0ukef> From: R-help on behalf of avi.e.gr...@gmail.com Sent: Tuesday, January 28, 2025 12:01:25 AM To: 'Naresh Gurbuxani' ; r-help@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 On Behalf Of Naresh Gurbuxani Sent: Monday, January 27, 2025 5:46 PM To: r-help@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 . Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my iPhone __ R-help@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@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]] __ R-help@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.
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 On Behalf Of Naresh Gurbuxani Sent: Monday, January 27, 2025 5:46 PM To: r-help@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 . Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my iPhone __ R-help@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. __ R-help@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.
Re: [R] R CMD check says no visible binding for global variable
This might be better for r-package-de...@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 . Status: 1 NOTE Is it possible to tell R CMD check that these variables are OK? Thanks, Naresh Sent from my iPhone __ R-help@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. __ R-help@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.