[Rd] parse_Rd raises error when example section contains a quoted percent character

peter dalgaard PDalgd at gmail.com
Tue Apr 12 18:38:58 CEST 2011


On Apr 12, 2011, at 18:24 , Jeffrey Horner wrote:

> I was writing Rd documentation for a new package when I came across
> this issue. Here's the smallest example:
> 
>> library(tools)
>> cat("\\examples{x <- '<%=rnorm(1)%>'}\n",file=file.path(tempdir(),'test.Rd'))
>> readLines(file.path(tempdir(),'test.Rd'))
> [1] "\\examples{x <- '<%=rnorm(1)%>'}"
>> parse_Rd(file.path(tempdir(),'test.Rd'))
> Error in parse_Rd(file.path(tempdir(), "test.Rd")) :
>  Unexpected end of input (in ' quoted string opened at test.Rd:1:17)
> In addition: Warning message:
> In parse_Rd(file.path(tempdir(), "test.Rd")) :
>  newline within quoted string at test.Rd:1
> 
> If I take out the percent characters, parse_Rd succeeds:
> 
>> cat("\\examples{x <- '<=rnorm(1)>'}\n",file=file.path(tempdir(),'test.Rd'))
>> parse_Rd(file.path(tempdir(),'test.Rd'))
> \examples{x <- '<=rnorm(1)>'}
> 
> So is this intended behavior or a bug? I would like to use the percent
> sign in a quoted string as it is part of brew syntax, and I'm writing
> example code to demonstrate such.

Semi-intended. % is the comment character in .Rd files, and there is no exception for verbatim code in \examples{} et al. So you need \% when it is not a comment. 


> 
>> sessionInfo()
> R version 2.13.0 RC (2011-04-12 r55422)
> Platform: i686-pc-linux-gnu (32-bit)
> 
> locale:
> [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
> [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] tools     stats     graphics  grDevices datasets  utils     methods
> [8] base
> 
> Jeff
> -- 
> http://biostat.mc.vanderbilt.edu/JeffreyHorner
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-devel mailing list