[R] Sweave question

Thomas Lumley tlumley at u.washington.edu
Tue Dec 23 17:40:34 CET 2003


On Tue, 23 Dec 2003, Rafael A. Irizarry wrote:

> 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")
> }
> @
>

I think your problem is with the `else'.  The `if' part of the statement
is syntactically complete, so the parser isn't expecting an `else'.  You
need something like

  if (exists("x")){
	plot(x,x)
  } else {
	plot(1,1,type="n")
  }



	-thomas




More information about the R-help mailing list