Skip to content

Still confused about classes

5 messages · Joshua Wiley, Brian Ripley, Kenn Konstabel +1 more

#
Hi Russ,

One tool that might help could be ?methods and ?showMethods

For example:
## for S3
methods(class = "Date")
## for S4
showMethods(classes = "Date")

regarding getting the actual year, I would use (though there may be
better ways):

format.Date(as.Date("2010-01-01"), format = "%Y")

HTH,

Josh
On Thu, Apr 28, 2011 at 11:05 PM, Russ Abbott <russ.abbott at gmail.com> wrote:

  
    
#
See ?months.

methods(class = "Date")

would have got you there.

(Date is not an S4 class, so people should not be setting S4 methods 
on it without very good reason, and there are none in R itself.)
On Thu, 28 Apr 2011, Joshua Wiley wrote:

            
Call format(), not its methods, or use strftime() directly.

  
    
#
The function for getting the year from date  is there in package
lubridate (as well as many other convenient functions to work with
dates).

More generally, finding "all" methods for a given class may be a
little tricky. If "all" means everything you have installed and
currently attached to your search path then methods(class="Date") will
do it (for S3 classes). (but "The functions listed are  those which
_are named like methods_ and may not actually be   methods (known
exceptions are discarded in the code). ") The result depends on which
packages you have loaded: in my currently open R session,
methods("Date") lists 36 "possible methods" but after library(zoo) I
get two more ( "as.yearmon.Date" and "as.yearqtr.Date").

Regards,
Kenn
On Fri, Apr 29, 2011 at 9:05 AM, Russ Abbott <russ.abbott at gmail.com> wrote: