Greetings, I have a problem that I am sure is very straightforward, but I just can't wrap my head around it. I've read the help pages on text, plotmath, expression, substitute, but somehow I can't find the answer to this simple question. Basically consider the following example: plot( NULL, xlim = c(0,2), ylim = c(0,2) ) expressions <- expression( -infinity, infinity ) text( c(0.5,1.5), 1.5, expressions ) labels <- c( "-infinity", "infinity" ) text( c(0.5,1.5), 0.5, as.expression(labels) ) I want the character vector "labels" to be interpreted as an expression vector, and so to appear just like the expressions vector. Is this possible? I mean yes, it is probably possible, but how? I suppose the problem is that the result of as.expression(labels) is expression("-infinity", "infinity") instead of expression(-infinity, infinity), as I would have liked. I just can't figure out how to convert it to the right thing. Haris
On 2/4/07, Charilaos Skiadas <skiadas at hanover.edu> wrote:> Greetings, > > I have a problem that I am sure is very straightforward, but I just > can't wrap my head around it. I've read the help pages on text, > plotmath, expression, substitute, but somehow I can't find the answer > to this simple question. > > Basically consider the following example: > > plot( NULL, xlim = c(0,2), ylim = c(0,2) ) > expressions <- expression( -infinity, infinity ) > text( c(0.5,1.5), 1.5, expressions ) > labels <- c( "-infinity", "infinity" ) > text( c(0.5,1.5), 0.5, as.expression(labels) ) > > I want the character vector "labels" to be interpreted as an > expression vector, and so to appear just like the expressions vector. > Is this possible? I mean yes, it is probably possible, but how?text( c(0.5,1.5), 0.5, parse(text=labels)) ? You need to parse the text to get to the expression Hadley
Try text( c(0.5,1.5), 0.5, parse(text = labels)) On 2/4/07, Charilaos Skiadas <skiadas at hanover.edu> wrote:> Greetings, > > I have a problem that I am sure is very straightforward, but I just > can't wrap my head around it. I've read the help pages on text, > plotmath, expression, substitute, but somehow I can't find the answer > to this simple question. > > Basically consider the following example: > > plot( NULL, xlim = c(0,2), ylim = c(0,2) ) > expressions <- expression( -infinity, infinity ) > text( c(0.5,1.5), 1.5, expressions ) > labels <- c( "-infinity", "infinity" ) > text( c(0.5,1.5), 0.5, as.expression(labels) ) > > I want the character vector "labels" to be interpreted as an > expression vector, and so to appear just like the expressions vector. > Is this possible? I mean yes, it is probably possible, but how? > > I suppose the problem is that the result of as.expression(labels) is > expression("-infinity", "infinity") instead of expression(-infinity, > infinity), as I would have liked. I just can't figure out how to > convert it to the right thing. > > Haris > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On Sun, 4 Feb 2007, Charilaos Skiadas wrote:> Greetings, > > I have a problem that I am sure is very straightforward, but I just > can't wrap my head around it. I've read the help pages on text, > plotmath, expression, substitute, but somehow I can't find the answer > to this simple question. > > Basically consider the following example: > > plot( NULL, xlim = c(0,2), ylim = c(0,2) ) > expressions <- expression( -infinity, infinity ) > text( c(0.5,1.5), 1.5, expressions ) > labels <- c( "-infinity", "infinity" ) > text( c(0.5,1.5), 0.5, as.expression(labels) ) > > I want the character vector "labels" to be interpreted as an > expression vector, and so to appear just like the expressions vector. > Is this possible? I mean yes, it is probably possible, but how? > > I suppose the problem is that the result of as.expression(labels) is > expression("-infinity", "infinity") instead of expression(-infinity, > infinity), as I would have liked. I just can't figure out how to > convert it to the right thing.The simplest way is almost certainly parse(text=labels). It is complicated by the fact that -infinity is a call and infinity is a symbol. -- 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
I keep forgetting that this list doesn't default to reply-to-all ;). Sorry hadley, you'll get this twice. On Feb 4, 2007, at 11:39 AM, Charilaos Skiadas wrote:> On Feb 4, 2007, at 11:19 AM, hadley wickham wrote: > >> text( c(0.5,1.5), 0.5, parse(text=labels)) ? >> >> You need to parse the text to get to the expression > > I just love the response rate and speed of this list, it's one of > the best lists I am subscribed to. Thank you all for your > responses, it makes more sense now (though I'll probably still want > to digest the whole thing in my head for a couple of days, to > understand exactly what is going on under the hood ;) ). > >> Hadley > > HarisHaris