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

Use vctrs to perform input validation #961

Merged
merged 10 commits into from
Sep 27, 2022
Merged

Use vctrs to perform input validation #961

merged 10 commits into from
Sep 27, 2022

Conversation

hadley
Copy link
Member

@hadley hadley commented Sep 23, 2022

No description provided.

R/map2.R Outdated Show resolved Hide resolved
src/map.c Outdated Show resolved Hide resolved
R/utils.R Outdated Show resolved Hide resolved
R/pmap.R Show resolved Hide resolved
R/pmap.R Show resolved Hide resolved
@DavisVaughan
Copy link
Member

Also FYI you'll need 3344411 for checks to pass again

R/pmap.R Outdated
@@ -100,12 +100,14 @@ pmap_chr <- function(.l, .f, ..., .progress = FALSE) {
}

pmap_ <- function(.type, .l, .f, ..., .progress = FALSE, ..error_call = caller_env()) {
.l <- vctrs_list_compat(.l)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we are ok with this?

pmap(NULL, identity)
#> list()

It used to error

Maybe worth a test, I feel like it is reasonable behavior (and maybe a test for a typed variant like pmap_dbl(NULL, identity)

@hadley hadley merged commit 0881a16 into main Sep 27, 2022
@hadley hadley deleted the vctrs-recycle-2 branch September 27, 2022 21:47
hadley added a commit that referenced this pull request Sep 27, 2022
Create new vctrs compatibility helper, and use it in a few places. "Weird" vectors like pairlists, expressions, and calls have been deprecated.
@@ -99,12 +99,31 @@ is_quantity <- function(x) {
x
}

vctrs_list_compat <- function(x, error_call = caller_env(), error_arg = caller_arg(x)) {
force(error_arg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? I thought part of the point of passing error_call and error_arg through in the specific way that we do is to avoid forcing the promises until they are actually required

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do it to get a good error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe preserve x by assigning the result of vctrs_vec_compat(x) to out instead of x?

I agree that the default pattern should be to evaluate these things lazily.

Copy link
Member

@DavisVaughan DavisVaughan Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I couldn't figure out what the problem was before but now I see that what Lionel suggests is a nice simple fix that maintains the standard pattern

vctrs_list_compat <- function(x, error_call = caller_env(), error_arg = caller_arg(x)) {
  out <- vctrs_vec_compat(x)
  vec_check_list(out, call = error_call, arg = error_arg)
  out
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, that's better. I pushed a fix to main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants