How to call multiple R commands in a single Custom R Command step

You can use the Custom R Command to run a single command you want. The command should take a data frame as a parameter and return a data frame. (e.g. mutate, filter, etc).

But, sometimes you want to run multiple R commands to process the given data frame in a single Custom R Command. You can do it with an anonymous function. Here is an example of adding new “x” and “y” columns. The anonymous function should take a data frame as a parameter (df in this example) and return a data frame. As long as you keep this rule, you can add any R commands inside the function.

(function(df){
  # Add your logic here.
  res <- df %>% mutate(x=10)
  res <- res %>% mutate(y="Test")
  # It should return a data frame.
  return (res)
})
1 Like