Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

R: How to write a function that replaces a function call in with another function call?

$
0
0

E.g. I want to transform the code

mean(x)

to

fn(x)

everytime I see mean in the code.

replace_mean <- function(code) {
  substitute(code, list(mean = fn)) # doesn't work
  substitute(substitute(code), list(mean = fn)) # doesn't work
}

the above two approaches don't work. E.g.

replace_mean(list(mean(y), mean(x)))

What's the best way to do function replacement using NSE in R?

Base R Solutions preferred.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>