[R] Line numbers in Sweave

Yihui Xie xie at yihui.name
Wed Nov 3 16:52:51 CET 2010


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.

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

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