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
Merged

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

merged 2 commits into from
Jul 5, 2019

Conversation

rcannood
Copy link
Contributor

@rcannood rcannood 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-
Copy link
Member

lionel- commented Jul 5, 2019

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

(@rcannood, #806).

@rcannood
Copy link
Contributor Author

rcannood 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
@lionel-
Copy link
Member

lionel- 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants