I encountered this bug doing the following (with R 2.14.1 on Linux using xemacs as the editor): > trace(tools::Rd2txt, edit=TRUE) Loading required package: tools # Edit and save file Error: '\d' is an unrecognized escape in character string starting "\d" > It isn't actually necessary to make any modifications with the editor for this to occur: exiting straight away still causes it. I believe the underlying problem is that when an object is being prepared for editing, the deparser does not correctly handle backslashes within backquoted strings. (If in the example above, the editor is used to double up all such backslashes before saving, then the error does not arise.) Andrew
Simpler version: > f <- function(x) switch(x,"\\dbc"=2,3) > dput(f) function (x) switch(x, `\dbc` = 2, 3) > f function(x) switch(x,"\\dbc"=2,3) > deparse(f) [1] "function (x) " "switch(x, `\\dbc` = 2, 3)" > parse(text=deparse(f)) Error: '\d' is an unrecognized escape in character string starting "\d" I.e. deparse/dput seems indeed to have a problem
Fixed in R-devel and R-patched.
On 29/03/2012 7:34 AM, r-bugs@r-project.org wrote: > https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14846 > > Peter Dalgaard<pd.mes@cbs.dk> changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > CC| |pd.mes@cbs.dk > > --- Comment #1 from Peter Dalgaard<pd.mes@cbs.dk> 2012-03-29 07:34:45 EDT --- > Simpler version: > > > > f<- function(x) switch(x,"\\dbc"=2,3) > > dput(f) > function (x) > switch(x, `\dbc` = 2, 3) > > f > function(x) switch(x,"\\dbc"=2,3) > > deparse(f) > [1] "function (x) " "switch(x, `\\dbc` = 2, 3)" > > parse(text=deparse(f)) > Error: '\d' is an unrecognized escape in character string starting "\d" > > > I.e. deparse/dput seems indeed to have a problem I think I have this fixed now. The same problem showed up in a number of locations in the deparse code, and I have tried to catch them all. The idea is to use the EncodeString function from the print routines; it knows how to escape things and add quotes. Will commit to R-devel and R-patched after some testing... Duncan Murdoch