On Thu, 3 Jan 2008, hodgess wrote:

>
>    Hi R people:
>
> On page 235 of the Blue Book (Becker, Chambers, and Wilks), there is a 
> "compose2" function.
>
> compose2 <- function(f,g) {
> gg <- substitute(g1(x))
> print(gg)
> gg[[1]] <- g
> ff <- substitute(f1(y))
> print(ff)
> ff[[1]] <- f
> ff[[2]] <- gg
> print(ff)
> fun <- function(x){ NULL }
> fun[[2]] <- ff
> fun
> }
>
> However, when I run this function using sum and log (as in the example), I 
> get the following error:
>
> Error in fun[[2]] <- ff : object of type 'closure' is not subsettable
>>
> Has anyone else run into this, please?
> Or is this a merely an issue with a dated concept, please?

The implementation of functions is different in S and in R.  You need to 
use body() and formals() in R (functions which did not exist in S).

>From memory, an n-arg function in S has n+1 components, the arguments plus 
the body.

> Thanks in advance,
> Sincerely,
> Erin Hodgess

-- 
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[email protected] 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