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

Allow %|% to work when y is of same length as x #806

Merged
merged 2 commits into from Jul 5, 2019

Conversation

Projects
None yet
2 participants
@rcannood
Copy link
Contributor

commented Jul 5, 2019

These changes allow x %|% y when y is of same length as x. For example:

> c(1L, NA, 3L, NA, NA) %|% 0L # usual use case
[1] 1 0 3 0 0
> c(1L, NA, 3L, NA, NA) %|% (6L:10L) # modified use case
[1]  1  7  3  9 10

Changes:

  • R/operators.R: I modified the documentation of %|% to reflect the changes in behaviour of this function. I also modified the stopifnot() checks accordingly.
  • src/lib/replace-na.c: Rather than looking at the length of y in replace_na_(), I created a separate function replace_na_vec_() and call the correct function depending on the length of y, as not to sacrifice speed by having more if/else statements.
  • tests/testthat/test-operators.R: I added tests to check whether x %|% y is working correctly when length(y) == length(x), and also that it produces an error when it is not.

@rcannood rcannood changed the title Allow `x %|% y` to work when `y` is of same length as `x`. Allow %|% to work when y is of same length as x Jul 5, 2019

@lionel-

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

Nice, thanks! Can you add a NEWS item please? It should end with:

(@rcannood, #806).

@rcannood

This comment has been minimized.

Copy link
Contributor Author

commented Jul 5, 2019

Done! 🙂

rcannood added a commit to dynverse/dynutils that referenced this pull request Jul 5, 2019

@lionel- lionel- merged commit c375d5b into r-lib:master Jul 5, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@lionel-

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

Thanks!

Please note that all vector functions will eventually move to the vctrs or funs packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.