Hi, I have written boxplot commands of this form before, but I don''t quite understand why the function call is reporting a syntax error in this instance. All parameters passed to the function are strings. Thanks in advance. Payam> simplevar <- function(wframe,column1,column2) {+ tframe <- get(wframe) + x1 <- which(names(wframe)==column1) + x2 <- which(names(wframe)==column2) + print(tframe[x1]) + print(tframe[x2]) + gtitle <- paste(names(tframe[x2])," vs. ", names(tframe[x1]) + quartz(width=7,height=5,dpi=200) Error: syntax error> boxplot(tframe[x2] ~ tframe[x1])Error in eval(expr, envir, enclos) : object ''tframe'' not found> > }[[alternative HTML version deleted]]
It appears you are missing a ")" gtitle <- paste(names(tframe[x2])," vs. ", names(tframe[x1])) <<= On Mon, Jun 15, 2009 at 1:54 PM, Payam Minoofar <payam.minoofar@meissner.com> wrote:> Hi, > > I have written boxplot commands of this form before, but I don't quite > understand why the function call is reporting a syntax error in this > instance. All parameters passed to the function are strings. > > Thanks in advance. > > Payam > > > simplevar <- function(wframe,column1,column2) { > + tframe <- get(wframe) > + x1 <- which(names(wframe)==column1) > + x2 <- which(names(wframe)==column2) > + print(tframe[x1]) > + print(tframe[x2]) > + gtitle <- paste(names(tframe[x2])," vs. ", names(tframe[x1]) > + quartz(width=7,height=5,dpi=200) > Error: syntax error > > boxplot(tframe[x2] ~ tframe[x1]) > Error in eval(expr, envir, enclos) : object 'tframe' not found > > > > } > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
On Mon, 2009-06-15 at 10:54 -0700, Payam Minoofar wrote:> Hi, > > I have written boxplot commands of this form before, but I don't quite > understand why the function call is reporting a syntax error in this > instance. All parameters passed to the function are strings.You're not seeing the wood for the trees. You get a syntax while defining the function. Hence there is an error in there and the function definition fails, R then treats the next line (boxplot(.....) ) as being a new statement and it complains about 'tframe' not being found - presumably because there is no object in your global environment with this name.> > Thanks in advance. > > Payam > > > simplevar <- function(wframe,column1,column2) { > + tframe <- get(wframe) > + x1 <- which(names(wframe)==column1) > + x2 <- which(names(wframe)==column2) > + print(tframe[x1]) > + print(tframe[x2]) > + gtitle <- paste(names(tframe[x2])," vs. ", names(tframe[x1])^^^^^^^^ Look like you are missing a ")" at the end of the line above. You haven't closed the call to paste()> + quartz(width=7,height=5,dpi=200) > Error: syntax error > > boxplot(tframe[x2] ~ tframe[x1]) > Error in eval(expr, envir, enclos) : object 'tframe' not found > > > > }I think you need to get a better R-aware editor that does bracket matching as the above is easy to spot in such an environment. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%