[Rd] Special characters in Rd example section will cause errors

From: Yihui Xie <xieyihui_at_gmail.com>
Date: Sat, 20 Jun 2009 22:18:43 +0800


Hi (Duncan?),

The other day I noticed some characters will cause errors in R CMD CHECK because of parse_Rd(), and AFAIK, these chars include '%', '{' and '}'. For example, note the comments in the example section:

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%

\name{testfun}
\Rdversion{1.1}
\alias{testfun}
\title{

A Test
}
\description{

A test
}
\usage{

testfun()
}
\value{

NULL
}
\author{

Yihui Xie
}
\examples{

# special characters in comments
# what if a bracket '{' here?
}
\keyword{ misc }
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%

## error occurs
> tools:::parse_Rd('testfun.Rd')
Error in tools:::parse_Rd("testfun.Rd") :   testfun.Rd:23:1: unexpected section header 23: }
24: \keyword

    ^

If I remove the '{', the Rd file can be parsed successfully. When you put a code line with "%" in it, there will also be an error, e.g. you put this in the example section

sprintf("%s", letters[1])

and you'll get

> tools:::parse_Rd('testfun.Rd')
Error in tools:::parse_Rd("testfun.Rd") :   Unexpected end of input (in " quoted string opened at testfun.Rd:23:10) In addition: Warning message:
In tools:::parse_Rd("testfun.Rd") :
  newline within quoted string at testfun.Rd:24

Rd_parse() will parse the Rd file incorrectly either.

> tools:::Rd_parse('testfun.Rd')
$meta
$meta$aliases
[1] "testfun"

$meta$concepts
character(0)

$meta$keywords
[1] "misc"

$meta$doc_type
character(0)

$meta$encoding
character(0)

$data

                                             vals        tags
1                                         testfun        name
2                                             1.1   Rdversion
3                                      \nA Test\n       title
4                                      \nA test\n description
5                                   \ntestfun()\n       usage
6                                        \nNULL\n       value
7                                   \nYihui Xie\n      author
8 \n# special characters in comments\n# what if ' examples

$rest

         examples
"'? or ''\n\n}\n"

Here is my session info:

> sessionInfo()
R version 2.9.0 (2009-04-17)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States. 1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base > R.version

               _
platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          9.0
year           2009
month          04
day            17
svn rev        48333
language       R

version.string R version 2.9.0 (2009-04-17)

Regards,
Yihui

--
Yihui Xie <xieyihui_at_gmail.com>
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China

______________________________________________ R-devel_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel

Received on Sat 20 Jun 2009 - 14:28:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 21 Jun 2009 - 15:00:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive