Apply a set of functions to an object : <p>I have a dataframe with a set of objects <code>df$data</code> and a set of rules to be applied on every object <code>df$rules</code>.</p>

<pre><code>df &lt;- data.frame(
  data = c(1,2,3),
  rules = c("rule1", "rule1, rule2, rule3", "rule3, rule2"),
  stringsAsFactors = FALSE
)
</code></pre>

<p>The rules are</p>

<pre><code>rule1 &lt;- function(data) {
  data * 2
}

rule2 &lt;- function(data) {
  data + 1
}

rule3 &lt;- function(data) {
  data ^ 3
}
</code></pre>

<p>For every row in the dataframe I want to apply all the rules specified in the <code>rules</code> column. The rules should be applied in series.</p>

<p>What I figured out:</p>

<pre><code>apply_rules &lt;- function(data, rules) {
  for (i in 1:length(data)) {
    rules_now &lt;- unlist(strsplit(rules[i], ", "))
    for (j in 1:length(rules_now)) {
      data[i] &lt;- apply_rule(data[i], rules_now[j])
    }
  }
  return(data)
}

apply_rule &lt;- function(data, rule) {
  return(sapply(data, rule))
}


apply_rules(df$data, df$rules)
# [1]   2 125  28
</code></pre>

<p>Although this works I'm pretty sure there must be more elegant solutions. On SO I could find lot's of stuff about the <code>apply</code>-functions and also one <a href="https://stackoverflow.com/questions/30979206/apply-many-functions-to-one-vector/30979677#30979677">post</a> about applying many functions to a vector and something about <a href="https://stackoverflow.com/questions/11330659/method-chaining-with-r/11331637#11331637">chaining functions</a>. The <code>Compose</code> idea looks promising but I couldn't figure out how to make a call to <code>Compose</code> with my rules as string. (<code>parse()</code> didn't work..)</p>

<p>Any hints?</p>
