[R] Sweave question

Douglas Bates bates at stat.wisc.edu
Tue Dec 23 17:28:52 CET 2003


Write the if-else statement as

if(exists("x")) {
	plot(x,x)
} else{
  plot(1,1,type="n")
  text(1,1,"data not available.\n")
}

so the first two lines are not syntactically complete.

"Rafael A. Irizarry" <ririzarr at jhsph.edu> writes:

> Using Sweave in the tools library (R version 1.8.0: sorry i havent 
> upgraded), it seems i cant use if statements in R chunks that make graphs. 
> i have this:
> 
> <<fig=TRUE,echo=F>>=
> par(mfrow=c(1,1))
> if(exists("x")) 
> 	plot(x,x)
> else{
>   plot(1,1,type="n")
>   text(1,1,"data not available.\n")
> }
> @
> 
> and I get this error:
> 
> Error:  chunk 6
> Error in parse(file, n, text, prompt) : parse error
> 
> any help is appreciated.
> 
> thanks and apologies if this not a problem in R 1.8.1
> rafael
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 
Douglas Bates                            bates at stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/




More information about the R-help mailing list