[R] evaluate variable within expression - how?

baptiste auguie baptiste.auguie at googlemail.com
Sun Feb 14 18:07:03 CET 2010


Hi,

Try with bquote,

plot.new()
myText <- "some text"
text(.5, .5, bquote(bold(.(myText))))

basically, bquote( .(myText) ) performs the substitution before
applying bold() (see ?bquote).

HTH,

baptiste


On 14 February 2010 17:36, Mark Heckmann <mark.heckmann at gmx.de> wrote:
> #  I want to plot bold text. The text should depend on a variable
> containing a character string.
>
> plot.new()
> text(.5, .5, expression(bold("Some text")))
>
> # now I would like to do the same replacing "some text" by a variable.
>
> plot.new()
> myText <- "some text"
> text(.5, .5, expression(bold(myText)))
>
> # This obviouyls does not work.
> # How can I combine substitute, parse, paste etc. do get what I want?
> # And could someone add a brief explanation what happens, as I find
> parse, expression, deparse, substitute etc. not easy to understand.
>
> Thanks,
> Mark
>
> –––––––––––––––––––––––––––––––––––––––
> Mark Heckmann
> Dipl. Wirt.-Ing. cand. Psych.
> Vorstraße 93 B01
> 28359 Bremen
> Blog: www.markheckmann.de
> R-Blog: http://ryouready.wordpress.com
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org 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.
>
>



More information about the R-help mailing list