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

**URL:** <https://community.exploratory.io/t/how-to-call-multiple-r-commands-in-a-single-custom-r-command-step/3032>\
**Category:** HowTo\
**Created:** [August 1, 2024, 4:37am UTC](https://community.exploratory.io/t/how-to-call-multiple-r-commands-in-a-single-custom-r-command-step/3032 "2024-08-01T04:37:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1](https://community.exploratory.io/user_avatar/community.exploratory.io/user1/32/11_2.png) [@user1](https://community.exploratory.io/u/user1)\
**Post date:** [August 1, 2024, 4:37am UTC](https://community.exploratory.io/t/how-to-call-multiple-r-commands-in-a-single-custom-r-command-step/3032/1 "2024-08-01T04:37:45Z")

</div>

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.

 ![image](https://community.exploratory.io/uploads/default/original/2X/5/585e0e47317549af9ad665a8a376fc08ce550e6d.png)

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

```
