From xie at yihui.name  Mon Jun 20 23:57:12 2011
From: xie at yihui.name (Yihui Xie)
Date: Mon, 20 Jun 2011 16:57:12 -0500
Subject: [Rd] Quote the path of graphics output in Sweave when it contains
	spaces
Message-ID: <BANLkTimwL+GEmXWBe4nroEJWTvF4uFStWA@mail.gmail.com>

Hi,

I'm aware of the definition of a "valid filename" in
.SweaveValidFilenameRegexp, but I think it might be better to quote
the filename when it contains spaces instead of just giving a warning.
This should bring us safer LaTeX code (although I never use spaces in
paths).

Here is the simple patch:

Index: src/library/utils/R/SweaveDrivers.R
===================================================================
--- src/library/utils/R/SweaveDrivers.R	(revision 56193)
+++ src/library/utils/R/SweaveDrivers.R	(working copy)
@@ -390,6 +390,8 @@
             }

             if (options$include) {
+                if (grepl("[[:space:]]", chunkprefix))
+                    chunkprefix = shQuote(chunkprefix, type = "cmd")
                 cat("\\includegraphics{", chunkprefix, "}\n", sep = "",
                     file = object$output)
                 linesout[thisline + 1L] <- srcline

Thanks!

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



[Rd] Quote the path of graphics output in Sweave when it contains spaces
Yihui Xie