Skip to content
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

condition handling ignores locally set options #6943

Open
moodymudskipper opened this issue Oct 25, 2023 · 1 comment
Open

condition handling ignores locally set options #6943

moodymudskipper opened this issue Oct 25, 2023 · 1 comment
Labels
bug an unexpected problem or unintended behavior

Comments

@moodymudskipper
Copy link

Maybe because of a delayed evaluation issue ?

bugged <- function() {
  withr::local_options(warn = 2)
  rlang::warn("oops") # or warning("oops")
  24
}

# as expected

bugged()
#> Error: (converted from warning) oops
subset(cars, speed == bugged())
#> Error: (converted from warning) oops

# unexpected

dplyr::filter(cars, speed == bugged())
#> Warning: There was 1 warning in `dplyr::filter()`.
#> ℹ In argument: `speed == bugged()`.
#> Caused by warning:
#> ! oops
#>   speed dist
#> 1    24   70
#> 2    24   92
#> 3    24   93
#> 4    24  120

Created on 2023-10-25 with reprex v2.0.2

@DavisVaughan DavisVaughan added the bug an unexpected problem or unintended behavior label Nov 6, 2023
@bart1
Copy link

bart1 commented Mar 27, 2024

I have been caught by a similar issue the other way around where warnings appear that should not be there:

require(dplyr)
#> Loading required package: 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
no_warn <- function() {
    withr::local_options(warn = -1)
    rlang::warn("oops") # some operation that produces a warning that should be ignored
    24
}
no_warn()
#> [1] 24
data.frame(a=1:2) %>% mutate(b=no_warn())
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `b = no_warn()`.
#> Caused by warning:
#> ! oops
#>   a  b
#> 1 1 24
#> 2 2 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants