Re: [R] lattice: calling functions

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed 15 Feb 2006 - 01:18:12 EST

On 2/14/2006 8:56 AM, Wolfram Fischer wrote:
> I defined three functions:
>

>> fun0 <- function( x=1:5, y=1:5, ... ) xyplot( y ~ x, ... )

>
>> fun1 <- function( x=1:5, y=1:5, ... ) fun2( y ~ x, ... )
>> fun2 <- function( ... ) xyplot( ... )

>
> The call of fun0() works as expected.
>
> The call of fun1() causes the following error:
> 'Error in eval(expr, envir, enclos) : object "y" not found'
>
> How should I define fun2 to avoid the error?

fun2 is fine, it's fun1 that has problems. It is passing a formula through fun2 to xyplot without telling xyplot where to evaluate the arguments. If you change it to

fun1 <- function( x=1:5, y=1:5, ... ) fun2( y ~ x, data=enviroment(), ... )

it will tell xyplot to look in the current environment at the time of the call, i.e. the fun1 evaluation environment where x and y live.

Duncan Murdoch



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 Received on Wed Feb 15 01:21:40 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:29 EST