Frage

Below is a minimal example:

\documentclass{article}
\begin{document}

<<data, results='hide', echo=FALSE, include=FALSE>>= 
library(rms)
fake.survival.data <- Surv(1:30, rep(1, 30))
fit <- survfit(fake.survival.data ~ 1)  
@

<<threeplots>>=
survplot(fit, xlab = "zeroth plot")

for(j in c("first plot", "second plot")){
  survplot(fit, xlab = j)
}
@

Of the two plots in the for-loop only the second is produced (in general: only the last). The problem seems to be with survplot specifically: if we add an ordinary plot after one of the survplots such as in:

\documentclass{article}
\begin{document}

<<data, results='hide', echo=FALSE, include=FALSE>>= 
library(rms)
fake.survival.data <- Surv(1:30, rep(1, 30))
fit <- survfit(fake.survival.data ~ 1)  
@

<<threeplots>>=
survplot(fit, xlab = "zeroth plot")
plot(c(1,1), xlab = "normal plot")
for(j in c("first plot", "second plot")){
  survplot(fit, xlab = j)
}
@

or:

   \documentclass{article}
\begin{document}

<<data, results='hide', echo=FALSE, include=FALSE>>= 
library(rms)
fake.survival.data <- Surv(1:30, rep(1, 30))
fit <- survfit(fake.survival.data ~ 1)  
@

<<threeplots>>=
survplot(fit, xlab = "zeroth plot")

for(j in c("first plot", "second plot")){
  survplot(fit, xlab = j)
  plot(c(1, 1) xlab = j)
}
@

all plots are produced where you expect them.

Does anyone know what happens here?

Thanks in advance, Vincent

War es hilfreich?

Lösung

This is due to a bug in the evaluate package. I have fixed it and sent the patch to the package author. For now, you can

library(devtools)
install_github('evaluate', 'yihui')
install_github('knitr', 'yihui')
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top