-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tidyverse "no visible binding for global variable" notes #2758
Comments
fixing no visible binding; see PecanProject#2758
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@dlebauer hello , is this issue still open ? if yes I would like to work on this. thankyou |
@moki1202 Yes, this issue is still open. We have hundreds of these notes that need to be addressed (e.g., for base/utils, base/db, modules/data.atmosphere). For each package, follow @dlebauer 's detailed instructions above. |
@ashiklom @infotroph We need to prepend only variables with .data$ that cause the run check error "no visible binding for global variable " . please correct me if I'm wrong. Some help on this issue would be appreciated. |
@moki1202 More or less. TLDR: You'll want to do this for any variables referring to column names in The root of the problem is that the library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
mydata <- tribble(
~food, ~category, ~price,
"apple", "fruit", 1.25,
"tomato", "vegetable", 1.40,
"cucumber", "vegetable", 1.70,
"orange", "fruit", 0.85,
"banana", "fruit", 0.30
)
mydata %>%
select(food, price)
#> # A tibble: 5 x 2
#> food price
#> <chr> <dbl>
#> 1 apple 1.25
#> 2 tomato 1.4
#> 3 cucumber 1.7
#> 4 orange 0.85
#> 5 banana 0.3
mydata %>%
filter(category == "fruit")
#> # A tibble: 3 x 3
#> food category price
#> <chr> <chr> <dbl>
#> 1 apple fruit 1.25
#> 2 orange fruit 0.85
#> 3 banana fruit 0.3
mydata %>%
mutate(price_cents = price * 100)
#> # A tibble: 5 x 4
#> food category price price_cents
#> <chr> <chr> <dbl> <dbl>
#> 1 apple fruit 1.25 125
#> 2 tomato vegetable 1.4 140
#> 3 cucumber vegetable 1.7 170
#> 4 orange fruit 0.85 85
#> 5 banana fruit 0.3 30
However, this can create some ambiguity. For instance, in the second column below, how can you be sure what price <- 1.00
cheap <- mydata %>%
filter(price > 0.9) More insidiously, the following expression will silently succeed if mydata %>%
select(-price) %>%
filter(price > 0.9)
# # A tibble: 5 x 2
# food category
# <chr> <chr>
# 1 apple fruit
# 2 tomato vegetable
# 3 cucumber vegetable
# 4 orange fruit
# 5 banana fruit
...but if This ambiguity is exactly the source of the warning from the R CMD check -- mydata %>%
filter(.data$price > 0.9)
#> # A tibble: 3 x 3
#> food category price
#> <chr> <chr> <dbl>
#> 1 apple fruit 1.25
#> 2 tomato vegetable 1.4
#> 3 cucumber vegetable 1.7
mydata %>%
select(.data$food, .data$price)
#> # A tibble: 5 x 2
#> food price
#> <chr> <dbl>
#> 1 apple 1.25
#> 2 tomato 1.4
#> 3 cucumber 1.7
#> 4 orange 0.85
#> 5 banana 0.3
mydata %>%
mutate(price_cents = .data$price * 100)
#> # A tibble: 5 x 4
#> food category price price_cents
#> <chr> <chr> <dbl> <dbl>
#> 1 apple fruit 1.25 125
#> 2 tomato vegetable 1.4 140
#> 3 cucumber vegetable 1.7 170
#> 4 orange fruit 0.85 85
#> 5 banana fruit 0.3 30 Created on 2021-02-17 by the reprex package (v1.0.0) |
@ashiklom thank you for the help. I tried to do my best to update the files here. some critical review would be highly appreciated for further work in base/db, modules/data.atmosphere. |
Thanks for your interest! Yes, this issue is still open, though we've made some progress on it -- #2773, #2774. In each PEcAn module, there is a file pecan/modules/benchmark/tests/Rcheck_reference.log Lines 59 to 60 in ee38544
Inside those files, look for messages like "No visible binding for global variable". Some of those are for |
@Sarthakaga15 Adding two details to @ashiklom's answer:
|
@Sarthakaga15 Feel free to ping me if you get stuck anywhere. I'm sure I can help you out in some places :) |
Hey I am newbie in open source and want to work on this issue is it still open ? and some resources would be helpful for me :D |
Hello @akshat-max! Glad you want to work on this. For now, you can refer to the conversation above for the description and the suggested solution. For starting, @Sarthakaga15 is working on fixing the no visible binding for global variables checks for PEcAn.workflow so pick up any package from modules and start working. If you get stuck somewhere feel free to ping me 😃. |
Yes it is! We have multiple PEcAn packages that need some fixing. I would suggest, you have a good look at the conversations above and start working! In case you get stuck somewhere feel free to mention me here. |
Thank you. Will give it a look and start working ASAP. |
@infotroph @dlebauer @moki1202 Hi, I am new to open source and would love to work on this issue if it's still open. |
@vaishase yes it is! there are still a lot of packages that need work. Pick a package and check the |
Sure, thanks! I'll look into it. |
Packages that still have this check warning:
Code to get this list:library(stringr)
library(purrr)
library(dplyr)
logs <- list.files(
pattern = "Rcheck_reference.log",
recursive = TRUE,
full.names = TRUE
)
logs |>
set_names(
dirname(logs) |> dirname() |> basename()
) |>
map_lgl(~{
readLines(.x) |>
str_detect("no visible binding for global variable") |>
any()
}) |> as_tibble(rownames = "package") |> filter(value) |
@moki1202 Hii , i think there are few more packages left that need to be checked and rendered , so if this issue is still open i would like to work on this , i have went through the above discussions , can i work on this issue !!? |
@harshagr70 please do, thanks! |
update outdated reference.log for resolved warnings
Adapted from discussion with @infotroph in #2756
no visible binding for global variable
NOTEs across all of PEcAn, and my wild guess is that half to two-thirds of these are Tidyverse calls.Shortcu:t For anyone who runs into this error and doesn't want to implement this fix: just add the appropriate note causing the build to fail to the package's
<pkg>/test/Rcheck_reference.log
, like this: 4a303b7If you are in a good place to tackle this: we support you, get comfy! Bonus points if you fix all of the issues in the package you are working on. A special prize if you fix all (currently 563) of these Notes.
TODO:
<pkg>/test/Rcheck_reference.log
filesfind . -name Rcheck_reference.log | xargs grep "no visible binding for global variable"
| wc -l
to the end of the line above.data$
as done here: https://github.com/PecanProject/pecan/pull/2756/files#diff-296112e719b8455a8be63e9cac941111d4ae1700081aa05b3a9adfa8d5b9738aR210##' @importFrom rlang .data
to<pkg>R/PEcAn.<pkgname>-package.R
. See PEcAn.DB for an example.<function name>: no visible binding for global variable <variable>
in<pkg>/test/Rcheck_reference.log
Alternative solutions:
<pkg>/test/Rcheck_reference.log
so that build ignores itSee also
Originally posted by @infotroph in #2756 (comment)
The text was updated successfully, but these errors were encountered: