Skip to content

R-beta: Including an evaluated function in text expression

2 messages · Matthew R. Nelson, Thomas Lumley

#
R-users,

I would like to take advantage of R's mathematical typesetting 
capabilities in the graphical environment using text(..., 
expression(...)), however, I can't figure out how to include in the 
expression some evaluated function.  For example,
# substituted for length(x) here

Is there a way to replace length(x) with the returned value of the 
function?

Thanks for any advice,

Matt
----------------------------------------------------------------------------
Matthew R. Nelson
Dept. of Human Genetics         
University of Michigan              http://www-personal.umich.edu/~ticul/
4711 Medical Science II             email: ticul at umich.edu
Ann Arbor, MI  48109-0618           phone: (313) 647-3151
----------------------------------------------------------------------------




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Fri, 27 Mar 1998, Matthew R. Nelson wrote:
Yes:
	R>text(5,5,parse(text=paste("sum(x[i],i==1,",length(x),")",sep="")))

What we do here is construct a string
	R> paste("sum(x[i],i==1,",length(x),")",sep="")
	[1] "sum(x[i],i==1,8)"
containing the returned value of length(x), and then
send it to the R parser. This returns a list of calls, ie, an expression.
	R> parse(text=paste("sum(x[i],i==1,",length(x),")",sep=""))
	expression(sum(x[i], i == 1, 8))
which is what you need to use as the argument to text().

	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._