Just for the archives, a partial answer to my question:

I was unable to find a definition for the Sinput environment that would work, but relatively minor changes to some of the RweaveLatex functions cause Sweave to generate SaveVerbatim environments rather than Sinput environments, and that's enough to get things to work. So the example below would be handled using

<<chunkname, eval=FALSE, saveVerbatim=TRUE>>=
x <- 1
@

somewhere safe, and then

\BUseVerbatim[fontshape=sl]{chunkname.in.1}

in the box. Each piece of input or output will be saved in a separate verbatim piece, and they each need to be used explicitly: you'll probably want to look at the .tex file to figure out the names.

This is pretty rough and I won't commit it to R, but I've attached the patch file (against R trunk rev 51988) in case anyone else wants to use it.

Duncan Murdoch

On 13/05/2010 10:19 AM, Duncan Murdoch wrote:
I'm trying to put together a poster using the LaTeX a0poster package and including some things from pstricks to get gradient shading, etc.

The problem is that the default environments used by Sweave don't work where I need them. A simple code chunk like

<<eval=FALSE>>=
x <- 1
@

buried in a minipage within a psshadowbox gives the error

Runaway argument?
 > x <- 1 \end {Sinput} \end {Schunk} and the resulting variable would\ETC.
D:/test.tex:302: Paragraph ended before \FV@
BeginScanning was complete


Has anyone solved this problem? One way I see that might work is to put the code chunk outside the environment and use SaveVerbatim to save it, then just put \BUseVerbatim or \LUseVerbatim in place where I need it. But because I'm using Sweave, I somehow need to redefine the Sinput, Soutput and maybe the Schunk environments to do that, and I don't see how to do so.
Duncan Murdoch

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

Index: Sweave.R
===================================================================
--- Sweave.R    (revision 51988)
+++ Sweave.R    (working copy)
@@ -368,7 +368,8 @@
                     split=FALSE, strip.white="true", include=TRUE,
                     pdf.version=grDevices::pdf.options()$version,
                     pdf.encoding=grDevices::pdf.options()$encoding,
-                    concordance=FALSE, expand=TRUE)
+                    concordance=FALSE, expand=TRUE,
+                    saveVerbatim=FALSE)
     options[names(dots)] <- dots
 
     ## to be on the safe side: see if defaults pass the check
@@ -482,8 +483,12 @@
                             thisline <- thisline + 1
                             openSchunk <- TRUE
                         }
-                        cat("\\begin{Sinput}",
-                            file=chunkout, append=TRUE)
+                        if (options$saveVerbatim) 
+                            cat("\\begin{SaveVerbatim}{", options$label, 
".in.", nce, "}", sep="", 
+                                file=chunkout, append=TRUE)                    
    
+                        else
+                            cat("\\begin{Sinput}",
+                               file=chunkout, append=TRUE)
                         openSinput <- TRUE
                     }
                    cat("\n", paste(getOption("prompt"), dce[1L:leading], 
sep="", collapse="\n"),
@@ -516,7 +521,10 @@
                 if(length(output) & (options$results != "hide")){
 
                     if(openSinput){
-                        cat("\n\\end{Sinput}\n", file=chunkout, append=TRUE)
+                       if (options$saveVerbatim) 
+                           cat("\n\\end{SaveVerbatim}\n", file=chunkout, 
append=TRUE)
+                       else
+                            cat("\n\\end{Sinput}\n", file=chunkout, 
append=TRUE)
                         linesout[thisline + 1L:2L] <- srcline
                         thisline <- thisline + 2L
                         openSinput <- FALSE
@@ -529,8 +537,12 @@
                             thisline <- thisline + 1L
                             openSchunk <- TRUE
                         }
-                        cat("\\begin{Soutput}\n",
-                            file=chunkout, append=TRUE)
+                        if(options$saveVerbatim)
+                            cat("\\begin{SaveVerbatim}{", options$label, 
".out.", nce, "}\n",
+                               sep="", file=chunkout, append=TRUE)
+                        else
+                            cat("\\begin{Soutput}\n",
+                               file=chunkout, append=TRUE)
                         linesout[thisline + 1L] <- srcline
                         thisline <- thisline + 1L
                     }
@@ -552,7 +564,10 @@
                     remove(output)
 
                     if(options$results=="verbatim"){
-                        cat("\n\\end{Soutput}\n", file=chunkout, append=TRUE)
+                       if (options$saveVerbatim)
+                           cat("\n\\end{SaveVerbatim}\n", file=chunkout, 
append=TRUE)
+                       else
+                            cat("\n\\end{Soutput}\n", file=chunkout, 
append=TRUE)
                         linesout[thisline + 1L:2L] <- srcline
                         thisline <- thisline + 2L
                     }
@@ -560,7 +575,10 @@
             }
 
           if(openSinput){
-              cat("\n\\end{Sinput}\n", file=chunkout, append=TRUE)
+             if (options$saveVerbatim) 
+                 cat("\n\\end{SaveVerbatim}\n", file=chunkout, append=TRUE)
+             else
+                 cat("\n\\end{Sinput}\n", file=chunkout, append=TRUE)
               linesout[thisline + 1L:2L] <- srcline
               thisline <- thisline + 2L
           }
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to