[R] Sweave cutting new lines

Florian Burkart florian.burkart at whu.edu
Thu Jun 10 14:44:25 CEST 2010


Hi,

I have trouble with Sweave (I think) cutting of my newlines.

As stated in the help of Sweave, I generate tex code straight from R for 
dynamically computed reports.

If I do this in R:

for (i in 0:4) {cat("\n",i,"\n")};cat("\n 3")

  0

  1

  2

  3

  4

  3

The output looks correct.

However, Sweave for some reason seems to trim everything outside 
forloops. Hence, this

<<results=tex,echo=FALSE>>=
sec<-0
lambda<-0
chartvalue<-"b"
relsec<-0
for (chartvalue in c("b","beta")) {
     for (relsec in 0:(e("count pd")-2)) {
         
file<-paste("working/frontfile",sec,"x",lambda,"x",chartvalue,"x",relsec,".pdf",sep="")
         pdf(file=file,paper="special",width=14,height=6)
         correl.plotsinglechart(sec,lambda,chartvalue,relsec)
         tmp<-dev.off()
         cat("\\includegraphics{",file,"}\n\n",sep="")
     }
}
chartvalue<-"rsq"
relsec<-0
file<-paste("working/frontfile",sec,"x",lambda,"x",chartvalue,"x",relsec,".pdf",sep="")
pdf(file=file,paper="special",width=14,height=6)
correl.plotsinglechart(sec,lambda,chartvalue,relsec)
tmp<-dev.off()
cat("\n\\newline\\includegraphics{",file,"}\n\n",sep="")
@

gets converted to this

\includegraphics{working/frontfile0x0xbx0.pdf}

\includegraphics{working/frontfile0x0xbx1.pdf}

\includegraphics{working/frontfile0x0xbx2.pdf}

\includegraphics{working/frontfile0x0xbetax0.pdf}

\includegraphics{working/frontfile0x0xbetax1.pdf}

\includegraphics{working/frontfile0x0xbetax2.pdf}\newline\includegraphics{working/frontfile0x0xrsqx0.pdf}



This actually works now because the \newline takes care of the line 
break, but it is not very pretty.


Does anyone know why Sweave behaves this way? Is there a way to fix it 
(besides working in another R chunk)? Maybe I am just being silly...

Thanks



More information about the R-help mailing list