From ripley at stats.ox.ac.uk  Mon Dec  6 20:49:40 2010
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 6 Dec 2010 19:49:40 +0000 (GMT)
Subject: [Rd] when to use pairlist instead list
In-Reply-To: <77EB52C6DD32BA4D87471DCD70C8D70003B1DD94@NA-PA-VBE03.na.tibco.com>
References: <77EB52C6DD32BA4D87471DCD70C8D70003B1DD94@NA-PA-VBE03.na.tibco.com>
Message-ID: <alpine.LFD.2.00.1012061924370.25014@gannet.stats.ox.ac.uk>

On Mon, 6 Dec 2010, William Dunlap wrote:

> I was writing some assertion tests for modelling-related
> code I had written and was surprised to see one test
> fail because the "specials" attribute of the output of
> terms() is a "pairlist" instead of a "list".  In 2.12.0
> I get:
>
>  > dput(attr(terms(y~Spec(x1)+x2, specials=c("Spec")), "specials"))
>  list(Spec = 2L)
>  >  all.equal(attr(terms(y~Spec(x1)+x2, specials=c("Spec")),
> "specials"), list(Spec=2L))
>  [1] "Modes: pairlist, list"
>  >  all.equal(attr(terms(y~Spec(x1)+x2, specials=c("Spec")),
> "specials"), pairlist(Spec=2L))
>  [1] TRUE
>  >  identical(attr(terms(y~Spec(x1)+x2, specials=c("Spec")),
> "specials"), pairlist(Spec=2L))
>  [1] TRUE
>
> I was wondering if there was a reason for using pairlist
> instead of list here or it it was just an historical
> artifact.  In general, when should one use pairlists?

Probably never directly.  But indirectly, a lot as for example 
argument lists are pairlists.

Looking at the code, I think this one is simply history.  For 
completeness I will correct ?terms.object.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] when to use pairlist instead list
Prof Brian Ripley