[R] combining mathematical notation and value substitution
Faheem Mitha
faheem at email.unc.edu
Sat Jun 21 01:15:32 CEST 2003
On Fri, 20 Jun 2003, Uwe Ligges wrote:
> Faheem Mitha wrote:
[snip]
> > main=paste("Monotonic Multigamma run (n=",
> > deparse(substitute(len)),", ",
> > expression(theta),"=", deparse(substitute(theta)),").")
>
> No, it won't work that way, because you have to specify an S expression
> in order to get mathematical annotation. An expression within paste()
> will be converted to a character string.
>
> What you ca do is the other way round:
>
>
> t1 <- theta # you cannot use theta as variable and math. symbol
> plot(1:10, main =
> substitute("Monotonic Multigamma run (" * n == len * ", " *
> theta == t1 * ").", list(len = len, t1 = t1)))
>
>
> See also ?plotmath or that small article in R News:
> Ligges (2002): R Help Desk: Automation of Mathematical Annotation in
> Plots. R News 2(3), 32-34.
Thank you for your help. Your expression works correctly. I've been trying
to understand why. I read your article, and I had already looked
previously at ?plotmath. However, the syntax of the above is still not
clear to me.
"Substitute" takes an expression as argument and substitutes the values of
any variables given in the second argument, correct? However, I am not
sure what it understands by
"Monotonic Multigamma run (" * n == len * ", " * theta == t1 *
Is this a valid expression? My understanding of an expression is that it
contains one more more statements. The R-lang manual says, not entirely
intelligibly
********************************************************************* "In
R one can have objects of type `"expression"'. An _expression_ contains
one or more statements. A statement is a syntactically correct collection
of tokens. Expression objects are special language objects which they
contain parsed, but unevaluated R statements. The main difference is that
an expression object can contain several such expressions. Another more
subtle difference is that objects of type `"expression"' are only
evaluated when explicitly passed to `eval', whereas other language objects
may get evaluated in some unexpected cases.
An expression object behaves much like a list and its components should be
accessed in the same way as the components of a list."
*********************************************************************
Firstly, I'm having difficulty parsing the sentence "Expression objects
are special language objects which they contain parsed, but unevaluated R
statements." Should the word "which" be removed? Then, the next sentence
says "The main difference is that an expression object can contain several
such expressions." The main difference from what? Lastly, if "An
expression object behaves much like a list" what are the individual
components? Are they expressions, and if so, how are they separated from
each other? I apologise for my cluelessness.
In any case, an expression object contains several statements, or several
expressions (not quite clear on the distinction). So, what are the
statements here?
You have character strings adjoined by eg. `n == len' which I agree is a
sensible statement. I'm guessing that R thinks of each character string as
a separate statement. If I do "foo" on the R command line it echoes it
back to me, but "foo" "bar" gives an error.
Can you explain what the `*' are doing here? Perhaps separating
statements? I've looked for use of this in a similar context but was
unable to find anything. Thanks again.
BTW, does "Introductory Statistics with R" by Peter Dalgaard, contain
disscussion of language issues, including "computing on the language"
stuff?
Faheem.
More information about the R-help
mailing list