Search code examples
rexpressionmagrittr

Is it possible to input an expression with the pipe %>% operator in R?


Why doesn't the pipe operator %>% work in the second example in the following code ?

library(magrittr) 

# Works
job::job({install.packages("gtsummary")})  
     
# Doesn't work
{install.packages("gtsummary")} %>% job::job()  
# Error in code[[1]] : object of type 'symbol' is not subsettable

Is this because the piped object is an expression ? I'm not familiar with expressions in R


Solution

  • Based on docs of magrittr library

    Technical notes The magrittr pipe operators use non-standard evaluation

    I think the problem comes from NSE algorithm in R

    as a workaround you can use the native pip operator like

    {install.packages("gtsummary")} |>  job::job()