Re: [R] Sweave and the "[" function

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 05 Sep 2006 - 11:46:06 GMT

Ross Darnell <r.darnell@uq.edu.au> writes:

> Hi Vincent
>
> This would seem logical but in this case doesn't work.
> It doesn't seem to be a Sweave problem (feature) at all but within R as
> Hadley stated.
> Within R try
>
> > quote(women[1])
> women[1]
>
> now try
>
> > quote("["(women,1))
> women[1]
>
> So it's parsed and "normalised" (there's a familiar term); in this case
> to women[1] before its quoted.
>
> Curiously in the "R Language Definition Guide" in 10.4.3 it states
>
> R has three indexing constructs, two of which are syntactically similar
> although with somewhat
> different semantics:
> object [ arg1, ...... , argn ]
> object [[ arg1, ...... , argn ]]
> The object can formally be any valid expression, but it is understood to
> denote or evaluate
> to a subsettable object. The arguments generally evaluate to numerical
> or character indices,
> but other kinds of arguments are possible (notably drop = FALSE).
> Internally, these index constructs are stored as function calls with
> function name "[" respectively
> "[[".

Clear enough to me, but then again, I probably wrote it... 5 years ago or so.

> So I'm lost now. Can some one hand me a map and compass?

Er, maybe, if you tell us which woods you are lost in so that we can find you...

What may be confusing you is that it is precisely the other way around: women[1] is parsed to "["(women,1) which deparses to women[1].

This may be illuminating:

for(i in 1:3) print(quote(foo(women,1))[[i]])
for(i in 1:3) print(quote("["(women,1))[[i]])
for(i in 1:3) print(quote(women[i])[[i]])

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch 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. Received on Tue Sep 05 21:51:13 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 07:51:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.