dieter.menne@menne-biomed.de
2002-Jul-04  14:00 UTC
groupedData constructor from a function (PR#1741)
Full_Name: Dieter Menne
Version: 1.5.1
OS: win2000
Submission from: (NULL) (212.185.252.139)
Package nlme, version 3.1-27 (but also in earlier)
Calling the groupedData constructor from a function may fail if the formula 
is not passed explicitely. Below a suggested patch 
Suggestions for patches are in the archives, by Thomas Lumley and saikat.
# http://finzi.psych.upenn.edu/R/Rhelp/archive/2250.html
Both are essentially correct, but probably untested (typos).
library(nlme)
data(Oxboys)
# make it a non-grouped data frame
ox<-as.data.frame(Oxboys)
# Changed by DM. See also
# http://finzi.psych.upenn.edu/R/Rhelp/archive/2250.html
# but there were a few typos in there
groupedData<-
function (formula, data = sys.parent(1), order.groups = TRUE, 
    FUN = function(x) max(x, na.rm = TRUE), outer = NULL, inner = NULL, 
    labels = NULL, units = NULL) 
{
    if (!(inherits(formula, "formula") && length(formula) == 
        3)) {
        stop("first argument to groupedData must be a two-sided
formula")
    }
    if (is.null(grpForm <- getGroupsFormula(formula, asList = TRUE))) {
        stop("Right hand side of first argument must be a conditional
expression")
    }
    ## patched part follow (may not work with S)
    mCall <- match.call()
    if (length(grpForm) == 1) {
      mCall[[1]] <- as.name("nfGroupedData") 
      eval(mCall, envir = parent.frame()) 
    }
    else {
      mCall[[1]] <- as.name("nmGroupedData") 
      eval(mCall, envir = parent.frame()) 
    }
    #######
}
 
ProcessPar<-function(par)
{
  form1<-as.formula(paste(par,"~age|Subject"))
  oxg3<-groupedData(formula=form1, data=ox)
  # Do processing with 
  print(str(oxg3))
}
# Works only with the patch to groupedData constructor
ProcessPar("height")
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._