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
I ran into inability to use !!as.name() with .x or .y input variables inside of mutate( map2( rename(...) ).
I provide a reprex with several attempts below.
Also I would like to add it is very strange but .x and .yglobal variables are not visible on the Environment tab in Data or Values sections in RStudio 1.3.1073. It is a problem if you used them for debugging previously without further rm(). The only way to know about their presence is to print them in the console.
library(tidyverse)
df<- tibble(
var_name="new_name",
data=list(data.frame(foo=1))
)
df#> # A tibble: 1 x 2#> var_name data #> <chr> <list> #> 1 new_name <df[,1] [1 x 1]>df$data#> [[1]]#> foo#> 1 1# OK example 1df %>% mutate(data= map2(data, var_name, ~.x %>% mutate(foo=.y))) %>% .$data#> [[1]]#> foo#> 1 new_name# OK example 2df %>% mutate(data= map(data, ~.x %>% rename(!!as.name("new_name") :=foo))) %>% .$data#> [[1]]#> new_name#> 1 1# ERROR example 1df %>% mutate(data= map2(data, "new_name", ~.x %>% rename(!!as.name(.y) :=foo)))
#> Error in as.name(.y): object '.y' not found# ERROR example 2df %>% mutate(data= map2(data, var_name, ~.x %>% rename(!!as.name(.y) :=foo)))
#> Error in as.name(.y): object '.y' not found# ERROR example 3df %>% mutate(data= map2(var_name, data, ~.y %>% rename(!!as.name(.x) :=foo)))
#> Error in as.name(.x): object '.x' not found# Example with global .y value 1.y<-"global"df %>% mutate(data= map2(data, var_name, ~.x %>% rename(!!as.name(.y) :=foo))) %>% .$data#> [[1]]#> global#> 1 1# Example with global .y value 2.y<-list("a")
df %>% mutate(data= map2(data, var_name, ~.x %>% rename(!!as.name(.y) :=foo))) %>% .$data#> Error in as.name(.y): invalid type/length (symbol/1) in vector allocation# repeating ERROR example 2
rm(.y)
df %>% mutate(data= map2(data, var_name, ~.x %>% rename(!!as.name(.y) :=foo))) %>% .$data#> Error in as.name(.y): object '.y' not found
The text was updated successfully, but these errors were encountered:
vovoch
changed the title
!!as.name() doesn't work with input variables inside of map2(mutate())
!!as.name() doesn't work with input variables inside of map2(rename())
Aug 31, 2020
vovoch
changed the title
!!as.name() doesn't work with input variables inside of map2(rename())
!!as.name() doesn't work with nested tibbles using map2()
Aug 31, 2020
vovoch
changed the title
!!as.name() doesn't work with nested tibbles using map2()
!!as.name() does not work with nested tibbles using map2()
Aug 31, 2020
This is expected. !! happens very early, at the time the first mutate() is called. At that point, the purrr lambda isn't executing yet, so there's no .x or .y argument.
We have plans to possibly change that in the next major version of rlang: r-lib/rlang#845. Maybe this would be too large of a breaking change and we can't go through with it.
I ran into inability to use
!!as.name()
with.x
or.y
input variables inside ofmutate( map2( rename(...) )
.I provide a reprex with several attempts below.
Also I would like to add it is very strange but
.x
and.y
global variables are not visible on the Environment tab in Data or Values sections in RStudio 1.3.1073. It is a problem if you used them for debugging previously without furtherrm()
. The only way to know about their presence is to print them in the console.Created on 2020-09-01 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: