Skip to content
Prev 9635 / 63421 Next

Interpretation of escaped characters in \examples{}

At 05:22 AM 26/05/2003, Kurt Hornik wrote:
Dear Kurt,

Thanks very much for this reference from the R-exts document. You don't 
address though the main point of my post, which is that the code displayed 
the online help and executed and checked by R CMD check is different from 
the code extracted and executed by the function 'example'.

Suppose I have an .Rd file for a function 'readFiles' containing the text 
'\examples{dir(pattern="\\\\.txt")}'. The quadruple-backlash will ensure 
that 'help' displays and R CMD checks the correct command 
'dir(pattern="\\.txt")'. However, if a user types 'example("readFiles")' at 
the R prompt, the command that R will execute is 'dir(pattern=".txt")'. 
This is *different command* and will generally give *wrong* results. There 
is no way that I can see to ensure that R CMD check and 'example' execute 
the same code.

My concern here is the with actual behavior of R rather than what R-exts 
says but, since you are emphasising the clarity of the R-exts document, it 
may be worth pointing out that R-exts also says

        \examples{...}
        Examples of how to use the function. These are set verbatim in 
typewriter font.

This seems to say that \examples{} is a verbatim environment rather than 
merely verbatim-like. This statement comes 4 pages earlier in the pdf 
version than the paragraph you quote.

Best wishes
Gordon