-
Notifications
You must be signed in to change notification settings - Fork 158
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
Surprising result with data.frame subset using dot #121
Comments
I think proper form would be to include in
or the very ugly
|
ahh, that is a good solution. works for a list too, thanks |
I probably should have included the aliases
I also caught an error in the answer above in the very ugly. I changed it to properly read.
|
Or even x %$% key[1] |
I just had a student run into a similar issue trying to convert latitude and longitudes. The following code produces the "wrong" output c(48,52) %>% sum(.[1], .[2]/60)
## [1] 148.8667 as it appears to be evaluating c(48,52) %>% {sum(.[1], .[2]/60)}
## [1] 48.86667 but this seems like very counter-intuitive behavior from magrittr. |
@rundel if I understood well the rules of the magrittr's main pipe operator, when you do x %>% f the interpreter will take c(48, 52) %>% (function(x) sum(x[1], x[2]/60)) as well. I'm sorry for any misunderstanding and would be grateful for any corrections. |
I ran into this today. A simple example:
My real problem is in data.table, where if I assign in a chain, I need to ask the object to print twice before I'll see it in the console. The usual approach is to add a [] on the end of the chain, but that breaks here without the
I'd prefer to use the [] approach rather than wrap in {} or add print, if that's possible. |
The "issue" is how the parser interpretes the calls to 1:3 %>% .[-1] %>% .[-1] and the other example: list(a = 1, b = 2) %>% stack %>%
setDT %>% setnames(c("v", "id")) %>% .[, id := as.character(id)] %>% .[] Whether that's preferable to an explicit |
Hi, apologies if this is user error or my misuse of the package.
I have simplified something I ran into to a very small reproducible example. Without the context, it probably doesn't make much sense why I would be doing this in the first place, but I hope that doesn't matter.
I have x, and want to return 'a.special.key:
I would expect the following to return "a.special.key"
but instead, it returns NA
I don't quite understand what order the eval is actually happening here, because both
x$key[1]
andx[1]$key
would return the proper text.digging into it, it seems the eval is
which is
NA
I am thinking I am just misusing the pipe and dot in this context (probably instead should
x%>% .[1,'key']
) but I thought the behavior was a bit unexpected and the documentation didn't mention a gotcha like thisIs this worth noting in the documentation? Maybe in {magrittr}?
The text was updated successfully, but these errors were encountered: