[R] Question on codetools and parse trees

Saptarshi Guha saptarshi.guha at gmail.com
Fri Jan 29 20:03:06 CET 2010


Dear R Users,
Using codetools I obtained the text representation of the parse tree for this
snippet


z=quote({x[1]<-2})
showTree(z)

>  ("{" (<- ([ x 1) 2))     (A)

If I understand correctly, x[1]<-2 ought to be "[<-"(x,1,2), so shouldn't i see

("{" ( [<- x 1 2 )  )

If indeed the parse tree in (A) is correct, the operation ([ x 1)
returns the value of x[1], how then does
the <- operator know to change the 1st element of x ? Does the <-
implementation inspect the its 1st argument (e.g if it sees
[ call, it instead changes itself to implementation of "[<-"?

Thank you
Saptarshi



More information about the R-help mailing list