Value of an R object in an expression
Just wanted to create an expression, existing of some mathematical annotation and a value of an R object. Wasn’t that intuitive!
Each single goal is easy to reach, for example to combine a value of an R object with text just use paste
:
To have a plot title with an \(\alpha_1\) you can use expression
:
But to let the the title of a plot contain objects and Greek letters isn’t that easy. Those of you who think it’s just about combining paste
and expression
might try it on their own and come back head-ached after few minutes of unsuccessful testings.
The problem is, that expression
interprets chars as expression and not as object identifier, of course, how should it know whether you mean the var alpha
or the Greek letter!? The solution is called substitute
! With substitute
you can replace objects inline, here is a small example:
You see, substitute
got a list what to substitute and replaces the v
in paste
with the content of var
. Run eval
to evaluate to result:
Now it’s easy to create a more complex plot title:
Go out and produce imposing graphs! (-;
Leave a comment
There are multiple options to leave a comment:
- send me an email
- submit a comment through the feedback page (anonymously via TOR)
- Fork this repo at GitHub, add your comment to the _data/comments directory and send me a pull request
- Fill the following form and Staticman will automagically create a pull request for you:
2 comments
[…] small example in action is presented in the image. In an earlier post I explained how to produce such a title consisting of R objects and Greek […]
Thank you, you helped me so much!!! :-D