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

Add a ptype argument to between() #7073

Merged
merged 14 commits into from
Aug 27, 2024

Conversation

JamesHWade
Copy link
Contributor

@JamesHWade JamesHWade commented Aug 15, 2024

Fixes #6906

Add ptype argument to between() function

This PR introduces a new ptype argument to the between() function, allowing users to specify the desired output type for comparisons. This enhancement is particularly useful when dealing with different data types or when specific type casting is required before comparison.

Key changes:

  1. Added ptype parameter to between() function
  2. Updated function logic to use ptype for casting when provided
  3. Added new tests to cover ptype functionality
  4. Updated documentation to explain the new argument

@DavisVaughan DavisVaughan changed the title Add a ptype argument to between Fixes #6906 Add a ptype argument to between() Aug 15, 2024
Copy link
Member

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

R/funs.R Outdated Show resolved Hide resolved
R/funs.R Outdated
left <- args$left
right <- args$right

Copy link
Member

Choose a reason for hiding this comment

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

These trailing spaces look odd, is this a setting in your editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not intentionally. I'm using Positron, which is still new to me.

Copy link
Member

Choose a reason for hiding this comment

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

I think you have to opt in to "files.trimTrailingWhitespace": true, in Positron settings, which we should probably considering automatically turning on in R files at least

I went ahead and fixed that up

R/funs.R Outdated Show resolved Hide resolved
Copy link
Member

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

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

Looking good! I first made a few tweaks of my own before leaving these comments, so make sure to git pull first before continuing your work to address these comments!

NEWS.md Outdated Show resolved Hide resolved
R/funs.R Outdated Show resolved Hide resolved
R/funs.R Outdated Show resolved Hide resolved
R/funs.R Outdated
Comment on lines 38 to 52
# But recycle to size of `x`
args <- vec_recycle_common(!!!args, .size = vec_size(x))
# Recycle to size of `x`
args <- vec_recycle_common(left = left, right = right, .size = vec_size(x))
Copy link
Member

Choose a reason for hiding this comment

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

If you do what we suggest above, then you can revert this part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm getting an error in my test when I try to revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error (test-funs.R:82:3): ptype argument works as expected with non-alphabetical ordered factors
Error in vec_recycle_common(!!!args, .size = vec_size(x)): Can't splice an object of type because it is not a vector.
Backtrace:

  1. ├─testthat::expect_identical(...) at test-funs.R:82:3
  2. │ └─testthat::quasi_label(enquo(object), label, arg = "object")
  3. │ └─rlang::eval_bare(expr, quo_get_env(quo))
  4. ├─dplyr::between(x, "c", "a", ptype = x)
  5. │ └─vctrs::vec_recycle_common(!!!args, .size = vec_size(x)) at dplyr/R/funs.R:55:3
  6. └─rlang::abort(message = message)

tests/testthat/test-funs.R Outdated Show resolved Hide resolved
tests/testthat/test-funs.R Outdated Show resolved Hide resolved
tests/testthat/test-funs.R Outdated Show resolved Hide resolved
tests/testthat/test-funs.R Outdated Show resolved Hide resolved
tests/testthat/test-funs.R Outdated Show resolved Hide resolved
tests/testthat/test-funs.R Outdated Show resolved Hide resolved
@DavisVaughan DavisVaughan merged commit e055527 into tidyverse:main Aug 27, 2024
11 checks passed
@DavisVaughan
Copy link
Member

Thanks @JamesHWade!

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.

Add a ptype argument to between() since we can't make it cast to the type of x at this time
3 participants