[R] Sweave question
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Dec 23 17:32:51 CET 2003
This is the standard problem with if ... else: that will not work at the
command line either. Use braces like
if(exists("x")) {
plot(x,x)
} else {
plot(1,1,type="n")
text(1,1,"data not available.\n")
}
which should do the trick.
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")
> }
> @
>
> 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
>
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list