[R] plotting an expression
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue May 1 01:03:07 CEST 2001
apjaworski at mmm.com writes:
> This is confusing, since
>
> substitiue(expression(cos(x)))
>
> returns just
>
> expression(cos(x)).
>
> Must be some side effects I do not understand. What is even more confusing
> is that the above code (with one line commented out) does not work when
> called as
>
> curve(parse(text="cos(x)"))
>
> although
>
> parse(text="cos(x)")
>
> returns
>
> expression(cos(x)).
You need to be very careful with expression()
For instance
> q <- quote(expression(cos(pi)))
> e <- eval(q)
> v <- eval(e)
> q
expression(cos(pi))
> e
expression(cos(pi))
> v
[1] -1
> mode(q)
[1] "call"
> mode(e)
[1] "expression"
Notice that q and e look similar, but behave differently and have
different modes. q is a call to the expression() function, e is an
object of mode expression. The object is being represented by the call
that generates it, (numeric(0)/quote(numeric(0)) is a similar
example). You can get to see what is inside as follows
> e[[1]]
cos(pi)
> q[[1]]
expression
> q[[2]]
cos(pi)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list