[R] lattice: defining an own function using args for formula and groups

2006-12-08 Thread Wolfram Fischer

x.fun - function( formula, data ) dotplot( formula, data )
x.grp - function( formula, groups, data ) dotplot( formula, groups, data )

data( barley )

 x.fun( variety ~ yield | site, data=barley )
# no problem

 dotplot( variety ~ yield | site, groups=year, data=barley )
# no problem

 x.grp( variety ~ yield | site, groups=year, data=barley )
object year not found # that's my error, so I do:

 x.grp( variety ~ yield | site, groups=barley$year, data=barley )
Error in eval(expr, envir, enclos) : numeric 'envir' arg not of length one

 traceback()
9: eval(substitute(groups), data, environment(formula))
8: bwplot.formula(x = formula, data = c(2, 2, 2, 2, 2, 2, 2, 2,  ...

Why it is a problem calling x.grp() and no problem calling x.fun() ?
What could I do to get work x.grp() ?

Thanks - Wolfram

__
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.


Re: [R] lattice: defining an own function using args for formula and groups

2006-12-08 Thread Gabor Grothendieck
Don't know of a more straight forward way but this works. It constructs
a new call to bwplot from the one to x.grp2 and evaluates it in the
parent environment:

library(lattice)
x.grp2 - function(x, groups, data) {
cl - match.call()
cl[[1]] - as.name(bwplot)
eval.parent(cl)
}

x.grp2( variety ~ yield | site, year, barley )


On 12/8/06, Wolfram Fischer [EMAIL PROTECTED] wrote:

 x.fun - function( formula, data ) dotplot( formula, data )
 x.grp - function( formula, groups, data ) dotplot( formula, groups, data )

 data( barley )

  x.fun( variety ~ yield | site, data=barley )
 # no problem

  dotplot( variety ~ yield | site, groups=year, data=barley )
 # no problem

  x.grp( variety ~ yield | site, groups=year, data=barley )
 object year not found # that's my error, so I do:

  x.grp( variety ~ yield | site, groups=barley$year, data=barley )
 Error in eval(expr, envir, enclos) : numeric 'envir' arg not of length one

  traceback()
 9: eval(substitute(groups), data, environment(formula))
 8: bwplot.formula(x = formula, data = c(2, 2, 2, 2, 2, 2, 2, 2,  ...

 Why it is a problem calling x.grp() and no problem calling x.fun() ?
 What could I do to get work x.grp() ?

 Thanks - Wolfram

 __
 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.


__
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.