[Rd] Sweave and absolute escaped backslashed Windows paths in R 2.12.0

Brian Diggs diggsb at ohsu.edu
Mon Oct 25 23:50:23 CEST 2010


I've noticed a change in behavior in R 2.12.0 from 2.11.1 regarding the 
treatment of absolute paths in the file argument of Sweave in a Windows 
environment.

Consider the minimal Rnw file, attached and reproduced below my 
signature in case .Rnw files get stripped.  This file is stored on my 
(Windows) computer in H:/My Documents.  Using an absolute path with the 
standard window's escaped backslahes path gives an error:

 > Sweave("H:\\My Documents\\test.Rnw")
Writing to file test.tex
Processing code chunks ...
  1 : echo term verbatim

Error:  chunk 1
Error : '\M' is an unrecognized escape in character string starting "H:\M"

Nothing in the chuck explicitly references the path, but something 
Sweave does triggers this.  This did not happen in 2.11.1.  Specifying 
the path using slashes or as a relative path works.

 > Sweave("H:/My Documents/test.Rnw")
Writing to file test.tex
Processing code chunks ...
  1 : echo term verbatim

You can now run LaTeX on 'test.tex'
 > Sweave("test.Rnw")
Writing to file test.tex
Processing code chunks ...
  1 : echo term verbatim

You can now run LaTeX on 'test.tex'

I discovered this problem from a feature ESS has which has a keybinding 
that executes Sweave using the command:

 > local({..od <- getwd(); setwd("h:\\My Documents\\"); Sweave("h:\\My 
Documents\\test.Rnw"); setwd(..od) })
Writing to file test.tex
Processing code chunks ...
  1 : echo term verbatim

Error:  chunk 1
Error : '\M' is an unrecognized escape in character string starting "h:\M"

I can certainly work around it by manually executing Sweave with slashed 
or relative paths, but it is an inconvient change in behavior that I 
don't recall seeing a reference to in NEWS.

I'm guessing something in Sweave is taking the string
"H:\\My Documents\\test.Rnw"
and turning it into
"H:\My Documents\test.Rnw"
which when treated as a string is not valid (as \M is not a valid 
escape).  However, I don't know what is doing this.  Could it be related 
to the ability to give context sensitive errors ("Parsing errors 
detected during Sweave() processing will now be reported referencing 
their original location in the source file.") which is new in 2.12.0?

 > sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

-- 
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University


test.Rnw:

\documentclass{article}

\begin{document}
<<>>=
1
@

\end{document}
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.Rnw
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20101025/4def1705/attachment.pl>


More information about the R-devel mailing list