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. 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"vito muggeo" <vito.muggeo at giustizia.it> writes:> 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. > > 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,That's because you changed y before the substitute(). Once you have changed it, it has no connection with the formal argument and is just a vector of numbers, which when deparsed gives a label like "c(34.159,45.6789,....)". You need something like yl<-deparse(substitute(y)) y<-y[(v+1):(n-v)] plot(y,type="l",lty=3,xlab="Time",ylab=yl) -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
vito muggeo 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. > > 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,Read ?substitute completely and you will see that the solution is: fn <- function(y, v=2){ dep.sub.y <- deparse(substitute(y)) n <- length(y) y <- y[(v + 1):(n - v)] plot(y, type = "l", lty = 3, xlab = "Time", ylab = dep.sub.y) } Note how wonderful readable the code above is. Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._