Hello,

I wonder if anyone has used the Compose() function in the 'roxygen' package. I 
find its behavior a bit surprising:

> f <- function(x) x + 1
> g <- function(x) x * 2
> f(g(2))
[1] 5
> Compose(f,g)(2)
[1] 6
> g(f(2))
[1] 6
> Compose(g,f)(2)
[1] 5

I would have expected Compose(f,g)(x) == f(g(x)) but it appears the order of 
application is reversed. It would be easy for me to modify with rev():
Compose <- function (...) {
  fs <- rev(list(...))
  function(...) Reduce(function(x, f) f(x), fs, ...)
}

But does the current implementation follow another convention I am unaware of?

Thanks -

Stephen

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to