[R] problem in deparse(substitute())
Emmanuel Paradis
paradis at isem.univ-montp2.fr
Wed Sep 18 13:48:25 CEST 2002
At 11:49 18/09/02 +0200, you wrote:
>Hi all,
>I am experiencing the following quite strange (at least in my knowledge)
>problem in a simple function like the following:
>
>fn<-function(y,v=2){
> n<-length(y)
> y<-y[(v+1):(n-v)]
> plot(y,type="l",lty=3,xlab="Time",ylab=deparse(substitute(y)))
> }
>
>fn(rnorm(50)) #look at the plot!!!
>
>The plot appears with numbers on the left side!
>If I delete the deparse(substitute()) in the ylab argument in the plot()
>function
>or I omit the line "y<-y[(v+1):(n-v)]" everything works well.
It seems that assigning this expression to an object called "y" gives some
trouble since "y" is used as an argument to the function too. Changing your
function to:
fn<-function(y,v=2){
n<-length(y)
yb<-y[(v+1):(n-v)]
plot(yb,type="l",lty=3,xlab="Time",ylab=deparse(substitute(y)))
}
sounds to give what you expect. It might be worth checking the R language
manual.
--
EP
>I can not test whether this problem depends on my R system (R 1.5.1 Win Me),
>but I have never had no problem before.
>
>many thanks for your help,
>
>bests,
>vito
>
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
.-.-
>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
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
._._
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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