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

magrittr operator %>% is evaluated before modules $ operator #43

Closed
mschubert opened this issue Nov 19, 2014 · 2 comments
Closed

magrittr operator %>% is evaluated before modules $ operator #43

mschubert opened this issue Nov 19, 2014 · 2 comments

Comments

@mschubert
Copy link
Collaborator

MWE from ebits, both b$min and sum have one required and one named default argument.

The first example that throws an error here should work. This might be an R bug though.

library(modules)
b = import('base')
c(1:100) %>% b$minN
# Error in `c(1:100)`$b : 3 arguments passed to '$' which requires 2
c(1:100) %>% (b$minN)
# [1] 2
c(1:100) %>% b$minN(N=2)
# [1] 2
c(1:100) %>% sum
# [1] 5050
c(1:100) %>% sum(na.rm=T)
# [1] 5050
@klmr
Copy link
Owner

klmr commented Nov 19, 2014

This is a “bug” in magrittr, not modules. However, they would probably argue that it’s by design1. The “correct” way to make this work is:

c(1:100) %>% b$minN()

However, I think it might be worth reporting this anyway, and see whether the magrittr folks agree.


1 It’s required to make the syntax foo %>% .$something work.

@klmr klmr closed this as completed Nov 19, 2014
@mschubert
Copy link
Collaborator Author

Yes, you are right.

I could also reproduce the example by putting a function in a list, without modules involvement.

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

No branches or pull requests

2 participants