From renaud at mancala.cbio.uct.ac.za  Thu Nov  3 15:21:53 2011
From: renaud at mancala.cbio.uct.ac.za (Renaud Gaujoux)
Date: Thu, 03 Nov 2011 16:21:53 +0200
Subject: [Rd] R CMD check and error in an \Sexpr in an Rd file
In-Reply-To: <438D2EC9EAFE5946B2D5864670EA468E08896B@MBXP01.ds.man.ac.uk>
References: <4EB281F4.3060109@cbio.uct.ac.za>, <4EB286E0.7070504@gmail.com>
	<438D2EC9EAFE5946B2D5864670EA468E08896B@MBXP01.ds.man.ac.uk>
Message-ID: <4EB2A381.60403@cbio.uct.ac.za>

Thank you Georgi.
With the fix \long the output is indeed consistent with the documentation.
I think my use of cat() worked by luck as its output should not have 
been rendered.

Would a 'results=tex' (html, text) be possible? or 'results=source' that 
could be combined with \if{format}{text}?
This would allow to generate custom Latex, or HTML code, but it might 
also be is hazardous...

Renaud

-- 
Renaud Gaujoux
Computational Biology - University of Cape Town
South Africa


On 03/11/2011 15:50, Georgi Boshnakov wrote:
> 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
>
>
> ________________________________________
> From: Duncan Murdoch [murdoch.duncan at gmail.com]
> Sent: 03 November 2011 12:19
> To: Renaud Gaujoux
> Cc: Georgi Boshnakov; r-devel at r-project.org
> Subject: Re: [Rd] R CMD check and error in an \Sexpr in an Rd file
>
> On 11-11-03 7:58 AM, Renaud Gaujoux wrote:
>> Georgi, I tried with paste() instead of cat(), but I then get the
>> following in my PDF manual:
>>
>> [1] "line\nnext line"
>>
>> i.e. what would be printed in the R console, which is not what I want.
>> I would like to get something like this in the Latex code:
>>
>> \begin{verbatim}
>> line
>> next line
>> \end{verbatim}
> I don't think you want that:  it forces display mode.  You might want
> verbatim text displayed inline, like \verb does.
>
>> Using cat() I get the following in the Latex code:
>>
>> \AsIs{
>> line
>> next line}
>>
>> which does not render as a new line in the PDF and breaks if empty lines
>> are present in the output text.
> So the problem is with the \AsIs macro.  You can see the definition in
> the Rd.sty file in R_HOME/share/texmf/tex/latex.  Can you suggest an
> improvement?
>
> Duncan Murdoch
>
>> Besides it will also break on \Sexpr[results=verbatim,
>> stage=render]{list("text", 3)}.
>>
>> But maybe this is not what 'results=verbatim' is supposed to do nor to
>> be used for?
>>
>> Renaud
>>
>> Another test Rd file.
>>
>> %%%%%%%%%
>> \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\nnext line\n")}
>>
>>       2: \Sexpr[results=verbatim, stage=render]{"line\nnext line\n"}
>>
>>       3: \Sexpr[results=verbatim, stage=render]{list("line\nnext 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\nnext line", 3)}
>>
>> }
>> %%%%%
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] R CMD check and error in an \Sexpr in an Rd file
Renaud Gaujoux