s-news
[Top] [All Lists]

[S] Proposal for S-Plus 5.0 and < 5.0 compatible handling of old classes

To: "s-news" <s-news@wubios.wustl.edu>
Subject: [S] Proposal for S-Plus 5.0 and < 5.0 compatible handling of old classes
From: "Frank E Harrell Jr" <fharrell@virginia.edu>
Date: Wed, 28 Apr 1999 21:31:31 -0400
Reply-to: "Frank E Harrell Jr" <fharrell@virginia.edu>
Sender: owner-s-news@wubios.wustl.edu
Tim Hesterberg of MathSoft has done a little bit of testing of the following
on S-Plus 5.x and it seems to work.  That leads to a change to existing
code so that one version will work both in 5.x and in versions before 5.0:

Old Coding                New Coding
k <- class(x)               k <- attr(x, 'class')
class(x) <- k               attr(x, 'class') <- k
w <- value; class(w) <- 'myclass' 
                                   w <- structure(value, class='myclass')

The last form is particularly handy for returning objects in functions.
The new approach gets around the non-backward compatibility of
class() in 5.x without resorting to the somewhat distasteful oldClass().
Unless someone sees a problem with this, I plan to use the above new
coding in making changes in my libraries so that they will be compatible with 
5.x.
Please don't blame Tim if there is a problem with this because neither he nor
MathSoft endorse it - Tim just let me know that it appears to work.

---------------------------------------------------------------------------
Frank E Harrell Jr
Professor of Biostatistics and Statistics
Director, Division of Biostatistics and Epidemiology
Dept of Health Evaluation Sciences
University of Virginia School of Medicine
http://hesweb1.med.virginia.edu/biostat


-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>