Q:

Passing a multivariable anonymous function in a Dplyr R pipe

Consider the following example dataframe
df  <- data.frame(x=c("A", "A", "B", "B"), y=c(1,2,1,2))

I am trying to understand how to use anonymous function with pipes
I would like to create another column type using an anonymous function
  x y  type
1 A 1 type1
2 A 2 type2
3 B 1 type2
4 B 2 type2

Of course I can use if_else():
df= df  %>%  mutate(type = if_else(.$x =='A' & .$y==1  , "type1",  "type2"))

but suppose  the if_else function doesn't exist and you want to use an anonymous function:
I know I can create the new column like this: 
df$type =mapply(df$x,df$y, FUN=function(x,y) if ((x=='A')  && (y==1))  "type1"   else "type2")

but I also want to use a pipe
df$type =df %>% mutate(type=mapply(.$x,.$y, FUN=function(x,y) if ((x=='A')  && (y==1))  "type1"   else "type2"))

yields the following:
  x y type.x type.y type.type
1 A 1      A      1     type1
2 A 2      A      2     type2
3 B 1      B      1     type2
4 B 2      B      2     type2

which gives two additional unwanted colunms. if I remove .$x and .$y I get an error
Thank you in advance

A:

What about this?
library(magrittr)
df %<>% mutate(type=mapply(.$x,.$y, FUN=function(x,y) if ((x=='A')  && (y==1))  "type1"   else "type2"))

