Skip to content
Prev 41667 / 63424 Next

R CMD check and error in an \Sexpr in an Rd file

Dear Duncan and Renauld,


The error caused by the empty line(s) can be removed by prefixin the macro with \long
in Rd.sty:

\long\def\Rd at AsIsX#1{\normalfont #1\egroup}

but the slash-n's come up in the output. 

In "text mode" this seems not to be a problem. Following normal TeX rules one needs to enter an empty line, e.g. by \n\n.

Having written that, I tried putting two \n's in the verbatim text and it seems to work (see below).

I need to consult the TeX book to be sure but the
problem with AsIs seems to be that by the time it starts processing its argument it has been tokenized by TeX
(hence single newlines have become spaces). 

Further thought may be needed about the new lines in verbatim. 
I may have missed again something but it seems that the observed output is consistent with the 
documentation, which states:

    "results=verbatim Print the results of the code just as if it was executed at the
    console, and include the printed results verbatim. (Invisible results will not print.)"

And the examples print on the console as they appear in output (with print, not cat).

Do we need exception from the general rule? 

An alternative would be to introduce results=verbatimLines option. 


Georgi

\name{Sexpr}
\alias{Sexpr}
\title{Error and verbatim in Sexpr}
\description{
    Testing Sexpr in Rd files

    %\Sexpr[results=verbatim, stage=render]{stop("error in sexpr")}

    Verbatim:

    1: \Sexpr[results=verbatim, stage=render]{cat("line\n\nnext line\n\n and another")}

%    1a: \Sexpr[results=text, stage=render]{capture.output(cat(c("line", "next line\n"),sep="\n", collapse="\n"))}

    2: \Sexpr[results=verbatim, stage=render]{"line\nnext line\n"}

    3: \Sexpr[results=verbatim, stage=render]{list("line\nnext line", 3)}

    4: \Sexpr[results=verbatim, stage=render]{list(c("line", "next line"), 3)}

    Text:

    1: \Sexpr[results=text, stage=render]{cat("line\nnext line\n")}

    2: \Sexpr[results=text, stage=render]{"line\nnext line\n"}

    3: \Sexpr[results=text, stage=render]{list("line\n\nnext  line\\\\\\\\ \\\\newline and another", 3)}

}



--
Dr Georgi Boshnakov               tel: (+44) (0)161 306 3684
School of Mathematics             fax: (+44) (0)161 306 3669
Alan Turing Building 1.125
The University of Manchester      email: Georgi.Boshnakov at manchester.ac.uk
Oxford Road
Manchester M13 9PL
UK