Hi,

I am constructing a plotting function that I would like to behave like
plotting functions within the lattice package. It takes a "groups" argument,
which I process, and then I would like to pass that argument on to the
xyplot function for the actual plotting. However, what ever I do, get an
error that the variable is missing.

A short illustration:

Given the data set

> names(pb)
[1] "Type"    "Sex"     "Speaker" "Vowel"   "IPA"     "F0"      "F1"
[8] "F2"      "F3"

and these test functions:

TESTFUN <- function(x,data,groups){

  xyplot(x,data=data,groups=groups)
}

TESTFUN2 <- function(x,data,groups){

  xyplot(x,data=data,groups=substitute(groups))
}

TESTFUN3 <- function(x,data,groups){
  groups <- eval(substitute(groups), data, environment(x))

  xyplot(x,data=data,groups=groups)
}

I fail to get "groups" to be passed on to xyplot correctly:

> TESTFUN(F1 ~ F2,data=pb,groups=Type)
Error in eval(expr, envir, enclos) : object 'groups' not found
> TESTFUN2(F1 ~ F2,data=pb,groups=Type)
Error in prepanel.default.function(groups = groups, x = c(2280L, 2400L,  :
  object 'groups' not found
> TESTFUN3(F1 ~ F2,data=pb,groups=Type)
Error in eval(expr, envir, enclos) : object 'groups' not found

Please help me understand what I am doing wrong.

/Fredrik

-- 
"Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it."

        [[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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to