R-beta: S Compatibility (again)

Thomas Lumley thomas at biostat.washington.edu
Sun Apr 12 18:59:38 CEST 1998

On Sun, 12 Apr 1998, Bill Venables wrote:
> 3. Language manipulation within R seems to be impossible.  I
>    realise this may be a design limitation that nobody can do
>    anything about, but it may be worth noting.
>    To be more specific, the R substitute() is much more limited
>    than the S version and coercion to mode "{", "call" or
>    "function" are unavailable, and function objects are not
>    subsetable.  as.call is useless and as.function only exists to
>    issue a rather tetchy error message.
>    For example, as far as I can see it is impossible to write a
>    version of the S function deriv() for R, short of getting down
>    to brass tacks and writing a new primitive into the base code,
>    but even then you can't extend it, of course.

While language manipulation is much more limited than in S, you probably
could write a version of deriv() (if it didn't already exist) since
expressions can be manipulated quite well.

R> a
expression(sin(cos(x + 1)))
R> a[[1]]
sin(cos(x + 1))
R> a[[1]][[1]]
R> a[[1]][[2]]
cos(x + 1)
R> a[[1]][[2]][[2]]
x + 1
R> a[[1]][[2]][[2]][[1]]
R> a[[1]][[2]][[2]][[2]]
R> a[[1]][[2]][[2]][[3]]
[1] 1
R> a[[1]][[1]]<-as.name("cos")
R> a
expression(cos(cos(x + 1)))

Thomas Lumley
Uni of Washington	
Box 357232		
Seattle WA 98195-7232	

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list