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

From: hadley wickham <h.wickham_at_gmail.com>
Date: Tue 05 Sep 2006 - 04:03:32 GMT

> <<>>=
> str(women)
> women$height
> women[,1]
> "["(women,1)
> @
>
> to show the equivalence of three methods of extracting an element from
> a data.frame.

>
> However Sweave returns the last of these as
>
> women[1]
>
> in the S input chunk
>
> How can I force it not to do this and return "["(women,1)

I don't think you can. Sweave parses your R code and from then on uses the internal R representation. R normalises the parse tree in certain ways (eg. strips comments, formats source code, and clearly normalises some function calls). Since sweave uses this, and not the original text, I don't think there is anyway to get around this, unless there is some trick during parsing.

(And don't forget women[[1]])

Hadley



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 16:20: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.