You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It also works with mutate when we write a separate function to do the same thing.
fun_group <- function(i){
data %>% mutate(!!paste0('col', i) := 1)
}
data %>% mutate(temp = map(i1, fun_group))
So why does 1 fail whereas 2 and 3 work fine. I have tried various modifications to the above to understand the reason but I failed to understand why it behaves differently. Tried changing data with mtcars, changing mutate with transmute but the error is still there.
The text was updated successfully, but these errors were encountered:
shahronak47
changed the title
Lazy eval
Lazy evaluation bug in mutate/transmute ?
Jan 6, 2021
That's because !! injection happens eagerly by the outermost data masking function. This is tracked in r-lib/rlang#845. We'll fix this in the next major release of rlang if it's not too much of a breaking change (people might rely on this behaviour).
This is inspired from this SO post . I have made a smaller and simpler example.
Consider this data :
Now let's say I want to add a new column
temp
to above dataframe which is going to be list of dataframes. I try :This returns
But it works if I use this without
mutate
:It also works with
mutate
when we write a separate function to do the same thing.So why does 1 fail whereas 2 and 3 work fine. I have tried various modifications to the above to understand the reason but I failed to understand why it behaves differently. Tried changing
data
withmtcars
, changingmutate
withtransmute
but the error is still there.The text was updated successfully, but these errors were encountered: