[R] a question of substitute

From: Adrian Dusa <dusa.adrian_at_gmail.com>
Date: Tue 09 Jan 2007 - 12:38:16 GMT

Hi all,

I want to write a wrapper for an analysis of variance and I face a curious problem. Here are two different wrappers:

fun.1 <- function(formula) {

    summary(aov(formula))
}

fun.2 <- function(formula) {

    oneway.test(formula)
}

values <- c(15, 8, 17, 7, 26, 12, 8, 11, 16, 9, 16,

            24, 20, 19, 9, 17, 11, 8, 15, 6, 14) group <- rep(1:3, each=7)

# While the first wrapper works just fine: fun.1(values ~ group)

# the second throws an error:
fun.2(values ~ group)
Error in substitute(formula)[[2]] : object is not subsettable

###

I also tried binding the two vectors in a data.frame, with no avail. I did find a hack, creating two new vectors inside the function and creating a fresh formula, so I presume this has something to do with environments.

Could anybody give me a hint on this?
Thank you,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed Jan 10 10:27:30 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 10 Jan 2007 - 04:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.