[R] Line numbers in Sweave

Duncan Murdoch murdoch.duncan at gmail.com
Wed Nov 3 17:22:31 CET 2010


On 03/11/2010 11:52 AM, Yihui Xie wrote:
> Well, I know this is true for the default Sweave(), and my problem
> actually comes from the pgfSweave package: I used some tricks to
> "cheat" R to parse and deparse the code chunks so that the output can
> be automatically formatted (and preserve the comments, [1]). The price
> to pay for not being "honest" is these line numbers since R 2.12.0
> (even if there are no errors in my code). As I am unable to figure out
> the logic behind Sweave() to generate line numbers, I cannot modify my
> code either. So a temporary dirty solution is to turn off the
> reporting of line numbers.

Could you be more specific?  I don't understand how the line numbers 
would affect anything if you don't have syntax errors.

> I wish the keep.source=FALSE option can preserve comments so that we
> don't need to touch utils:::RweaveLatexRuncode ([2]).

This is basically impossible:  with keep.source=FALSE, you are just 
seeing deparsed code.  The comments don't make it into parsed code, so 
the deparser never sees them.

I don't know the evaluate package, but I think I remember that the 
highlight package has its own parser, it doesn't use R's.  Perhaps R's 
parser could import some of the differences, but I think it's 
complicated enough as it is, and would rather not make it more so.


> Formatting the
> code chunks is really a nice feature with keep.source=FALSE, but the
> price of discarding comments is too high... I think the evaluate
> package might be a good place to look at (or perhaps the highlight
> package), which performs just like the R terminal (keep the comments
> and report the errors without really stopping R, [3]).

The error in [3] is a run-time error, not a syntax error.  It should be 
unaffected by the line numbers.

Duncan Murdoch

> Thanks!
>
> [1] https://github.com/cameronbracken/pgfSweave/blob/master/R/pgfSweaveDriver.R#L297
> [2] http://yihui.name/en/wp-content/uploads/2009/11/Sweave2.pdf
> [3] see the error in the last but one example:
> http://had.co.nz/ggplot2/stat_smooth.html
>
> Regards,
> Yihui
> --
> Yihui Xie<xieyihui at gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
>
> On Tue, Nov 2, 2010 at 5:09 PM, Duncan Murdoch<murdoch.duncan at gmail.com>  wrote:
> >  On 02/11/2010 5:50 PM, Yihui Xie wrote:
> >>
> >>  Hi,
> >>
> >>  I thumbed through the source code Sweave.R but was unable to figure
> >>  out when (under what conditions) R will insert the line numbers to the
> >>  output. The R 2.12.0 news said:
> >>
> >>       • Parsing errors detected during Sweave() processing will now be
> >>         reported referencing their original location in the source file.
> >>
> >>  Do we have any options to turn off this reporting? Thanks!
> >
> >  Sure:  just don't include any syntax errors.
> >
> >  Duncan Murdoch
> >



More information about the R-help mailing list