[datatable-help] Error: no method or default for coercing "character" to "IDate"
Steve Lianoglou
mailinglist.honeypot at gmail.com
Wed Jul 27 17:10:37 CEST 2011
Hi,
On Wed, Jul 27, 2011 at 10:20 AM, Chris Neff <caneff at gmail.com> wrote:
> Hi all,
> Using read.csv's colClasses argument with a date column tagged as IDate
> doesn't work. Distilling it down it is the following.
> This works:
> as.IDate("2010/11/01")
> but this doesn't (and is what read.csv uses):
> as("2010/11/01","IDate")
>
> I'm not familiar enough with the class semantics any more to remember, but
> any reason why this isn't doable?
This is definitely doable.
Matthew has been making several updates to data.table, and I think
wants to release another version soon (no ETA on that from me,
though).
We can get that into the codebase before the next release, for sure.
The additions are simple, though, so if you can't wait for that, you
can drop these few lines somewhere in your codebase and have it loaded
into your R workspace. It should enable the functionality you need:
setOldClass("IDate")
setOldClass("ITime")
setAs("character", "IDate", function(from) as.IDate(from))
setAs("character", "ITime", function(from) as.ITime(from))
With that "loaded up", you can then do:
R> as("2011-01-01", "IDate")
[1] "2011-01-01"
HTH,
-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the datatable-help
mailing list