[R] expressions and paste

Thomas Lumley tlumley at u.washington.edu
Thu Nov 11 18:26:06 CET 2004

On Thu, 11 Nov 2004, Emily Baldock wrote:

> I have written a function to plot data which will be used for various different chemistries.
> A simplified version is:
> plot_data <- function(risk,levels,chem,sd2,measure){
>  plot(risk, levels,main=paste ("per", sd2, measure, "\n in usual", chem))
> }
> The problem is with the title.
> This works fine if the variable "chem" is just text, but if it is an expression then obviously it won't work.
> I have experimented with various things and I am at a complete loss for how to insert an expression into the middle of
> a title.

You can use
  plot(1,1,main=bquote("per "*.(sd2)*.(measure)*" in usual "*.(chem)))
  plot(1,1,main=substitute("per "*sd2*measure*" in usual "*chem,
    list(sd2=sd2,measure=measure,chem=chem)) )

You don't get the newlines, someone else will have to work this out.


More information about the R-help mailing list