[R] Access to conditioning variables (lattice)

Deepayan Sarkar deepayan.sarkar at gmail.com
Sun Oct 4 15:35:14 CEST 2009

On Thu, Sep 24, 2009 at 2:14 PM, Martin Lepage
<martin.d.lepage at gmail.com> wrote:
>> The problem I am facing is that I do not know how to generically access
>> the conditioning variables within the panel function. In this simple
>> case, I can achieve what I want to do with the following call :
>>    do_something_with(Type[which.packet()])
> I just continued testing and I realized that the last line I wrote only
> worked on my test session because I had a object named 'Type'
> that existed in the workplace :
>    Type <- dataset.Type
> I cannot access the xyplot 'data$Type' object from within the panel
> function (although dataset$Type obviously works).
> I will continue my search through the documentation and report any
> success.

The way to pass extra variables to panel functions is to add arguments
to the high-level call, e.g.,

xyplot( y ~ x | Type, dataset,
       type.var = dataset$Type,
       type.levels = levels(dataset$Type)
       panel = function(..., type.var, type.levels) {

The fact that the extra variable here is a conditioning variable is a
coincidence. There is no special mechanism to access conditioning
variables inside the panel function.


More information about the R-help mailing list