-
Notifications
You must be signed in to change notification settings - Fork 285
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
Check read_builtin()'s inputs #1361
Conversation
This is in reponse to a request from CRAN. Previously this expectation: expect_error(read_builtin(AirPassengers, "datasets")) would call `utils::data()` on malformed input. Eventually that lead to some condition having length greater than 1. So we got an error, but an error that indicates a programming problem. I think this means `utils::data()` might have a condition length problem, but it's not my problem. Instead, I'll be more careful to catch obviously bad input in readr itself. I was able to reproduce what CRAN reported with released R (they used R-devel) with env var settings such as: _R_CHECK_LENGTH_1_CONDITION_=verbose _R_CHECK_LENGTH_1_CONDITION_="abort,verbose" Note that "true" is not enough to surface the issue, because the offending code is inside expect_error().
@DavisVaughan I don't think there's anything particularly tricky here, just looking for another set of 👀 since I decided to create a typical |
tryCatch( | ||
warning = function(e) warn_to_error(e), | ||
expr = { | ||
res <- utils::data(list = list(x), package = package, envir = environment(), verbose = FALSE) | ||
res <- utils::data(list = x, package = package, envir = environment(), verbose = FALSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original list(x)
was sort of a mistake. The list
argument of utils::data()
is supposed to be a character vector (despite its confusing name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I've done more tests now and this really is the mistake, at least on our end. Just fixing this alone would be enough to avoid triggering "the condition has length > 1". But I think we might as well check the inputs and deliver a more informative error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it a little silly that the argument is named list
but wants a character vector 😛
Agreed that this was a bug on our end.
NEWS.md
Outdated
@@ -4,6 +4,8 @@ | |||
|
|||
* `show_progress()` uses `rlang::is_interactive()` instead of `base::interactive()` (#1356). | |||
|
|||
* `read_builtin()` does more argument checking, so that we catch obviously malformed input before passing along to `utils::data()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is kind of a chicken and egg problem, but if you don't have an issue open for this problem then I tend to open the PR, document the issue in the PR like you have done, then do another commit that would add (#1361)
to the NEWS bullet. It is annoying that you can't do that on a first pass, but you don't know the PR number (for sure) until you open it.
tryCatch( | ||
warning = function(e) warn_to_error(e), | ||
expr = { | ||
res <- utils::data(list = list(x), package = package, envir = environment(), verbose = FALSE) | ||
res <- utils::data(list = x, package = package, envir = environment(), verbose = FALSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it a little silly that the argument is named list
but wants a character vector 😛
Agreed that this was a bug on our end.
@@ -190,3 +190,13 @@ readr_enquo <- function(x) { | |||
} | |||
x | |||
} | |||
|
|||
check_string <- function(x, nm = deparse(substitute(x)), optional = FALSE) { | |||
if (rlang::is_string(x)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate that this also catches NA_character_
, which the previous checks would have allowed
CRAN has accepted the patch version of readr where we've fixed this multiple ways (v2.1.2). But, as predicted, I note that base R just gained a check that the |
I noticed this because readr v2.1.1 (the previous, unfixed version) just started to fail on one of CRAN's r-devel flavours. This should self-resolve when CRAN's readr checks pick up the new version (v2.1.2).
|
This is in reponse to a request from CRAN.
Previously this expectation:
would call
utils::data()
on malformed input, i.e. intentionally calling with the symbolAirPassengers
. Eventually that lead to some condition having length greater than 1. So we got an error, alright, but an error that indicates a programming problem.I think this means
utils::data()
might have an input-checking problem, but it's not my problem.Instead, I'll be more careful to catch obviously bad input in readr itself.
I was able to reproduce what CRAN reported with released R (they used R-devel) with env var settings such as:
Note that "true" is not enough to surface the issue, because the offending code is inside
expect_error()
.