Hi all, what is the recommended way to quickly (and without much burden on the memory) extract the response from a formula?
The standard way to extract the response from a formula seems to be via model.frame() or model.extract(), but that is very memory intensive. Here is a quick example, that (BEWARE) consumes a lot of memory: --8<---------------cut here---------------start------------->8--- require("ALL") data("ALL") y <- pData(ALL)$sex x <- t(exprs(ALL)) mf <- cbind(as.data.frame(x), y=y) extractResponse <- function(formula, data) { m <- match.call(expand.dots = FALSE) m[[1L]] <- quote(stats::model.frame) m <- eval.parent(m) y <- model.extract(m, "response") y } extractResponse(y~., data=mf) extractResponseFast <- function(formula, data) { y <- eval(as.symbol(as.character(formula)[2]), environment(formula)) y } extractResponseFast(y~., data=mf) --8<---------------cut here---------------end--------------->8--- Or, to put my question differently, is the following approach robust? --8<---------------cut here---------------start------------->8--- require("ALL") data("ALL") y <- pData(ALL)$sex x <- t(exprs(ALL)) mf <- cbind(as.data.frame(x), y=y) extractResponseFast <- function(formula, data) { y <- eval(as.symbol(as.character(formula)[2]), environment(formula)) y } extractResponseFast(y~., data=mf) --8<---------------cut here---------------end--------------->8--- Many thanks in advance! Regards, Andreas ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.