Gijs Plomp
2004-Jul-08 10:23 UTC
[R] How to pass strings to functions? [once once more, now With content I hope...]
Dear expeRts, I fail to succesfully pass strings to functions. It comes down to the observation that > plot(someVariable,anotherVariable) works fine, but > x <- "someVariable" > y <- "anotherVariable" > plot(x,y) does not. Does this have something to do with the returned value of x being /"someVariable"/ and not /someVariable/, i.e. without the quotation marks? Is there any way to work around this? Ultimately I'd like to make multiple graphs by looping throught the values in vectors. Something like: > var<-c(var1,var2...n) > for (v in var) >{ > plot(var, x)) >} I've looked around for help on this but am stuck. Hope you can help, Gijs Plomp
Uwe Ligges
2004-Jul-08 11:04 UTC
[R] How to pass strings to functions? [once once more, now With content I hope...]
Gijs Plomp wrote:> Dear expeRts, > > I fail to succesfully pass strings to functions. It comes down to the > observation that > > > plot(someVariable,anotherVariable) > > works fine, but > > > x <- "someVariable" > > y <- "anotherVariable" > > plot(x,y)Do you mean x <- someVariable y <- anotherVariable plot(x,y) Why are you not calling plot(someVariable, anotherVariable)> does not. > > Does this have something to do with the returned value of x being > /"someVariable"/ and not /someVariable/, i.e. without the quotation > marks? Is there any way to work around this? > > Ultimately I'd like to make multiple graphs by looping throught the > values in vectors. Something like: > > var<-c(var1,var2...n) > > for (v in var) > >{ > > plot(var, x)) > >}Does not make sense. You need to use "v" within the loop..... But I don't know what you are intending? You still need to be more specific! Uwe Ligges> I've looked around for help on this but am stuck. > > Hope you can help, > Gijs Plomp > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
Matthias.Kohl@uni-bayreuth.de
2004-Jul-08 11:08 UTC
[R] How to pass strings to functions? [once once more, now With content I hope...]
> Dear expeRts, > > I fail to succesfully pass strings to functions. It comes down to the > observation that > > > plot(someVariable,anotherVariable) > > works fine, but > > > x <- "someVariable" > > y <- "anotherVariable" > > plot(x,y) > > does not. > > Does this have something to do with the returned value of x being > /"someVariable"/ and not /someVariable/, i.e. without the quotation > marks? Is there any way to work around this? > > Ultimately I'd like to make multiple graphs by looping throught the > values in vectors. Something like: > > var<-c(var1,var2...n) > > for (v in var) > >{ > > plot(var, x)) > >} >what about plot(get(v), x)?> I've looked around for help on this but am stuck. > > Hope you can help, > Gijs Plomp > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
Thomas Lumley
2004-Jul-09 03:30 UTC
[R] How to pass strings to functions? [once once more, now With content I hope...]
On Thu, 8 Jul 2004, Gijs Plomp wrote:> Dear expeRts, > > I fail to succesfully pass strings to functions. It comes down to the > observation that > > > plot(someVariable,anotherVariable) > > works fine, but > > > x <- "someVariable" > > y <- "anotherVariable" > > plot(x,y) > > does not. > > Does this have something to do with the returned value of x being > /"someVariable"/ and not /someVariable/, i.e. without the quotation > marks? Is there any way to work around this? >This is in the FAQ. -thomas