R/S compatibility in passing a formula
Prof Brian D Ripley
ripley@stats.ox.ac.uk
Sun, 11 Apr 1999 08:39:59 +0100 (BST)
On 11 Apr 1999, Peter Dalgaard BSA wrote:
> Douglas Bates <bates@stat.wisc.edu> writes:
>
> > In S3 if you are passing an evaluated formula to another function that
> > will store it and use it in printing (such as a model-fitting function), you
> > usually want to unclass the formula. Otherwise, the formula that gets
> > stored looks very ugly when printed. A trick to do the unclassing is to pass
> > form = c( myFormula )
> > In R this has the effect of making form a list rather than a call. It
> > seems that passing
> > form = as.vector( myFormula )
> > will work in both dialects. Anyone else have experience with this?
>
> Apparently
>
> (a) R does not print the class on a formula (because print.formula
> unclasses it)
> (b) as.vector does not unclass in R but does in S3. Try
> class(as.vector(form))
>
> So the result of as.vector *looks* alike, but isn't. Smells like
> trouble...
>
> Whatever is wrong with using unclass() for unclassing anyway??
Because it is oldUnclass in recent S's, and having to use code translators
for S3/R/S-PLUS 5.x is a pain! Nevertheless, that is what I do: write
oldUnclass() and translate. (The reverse does not work: in S-PLUS 5 one
sometimes needs unclass()).
(I am pickily using S-PLUS 5 not S4: there is no public version of S4, but
S-PLUS 5 is quite different from S4 as documented in Chambers, 1998.)
--
Brian D. Ripley, ripley@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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._