What is the big value to having a class change anyways? I would generally say that since the use case is that people want to be able to use characters/dates as factors it should automatically convert these as data.table does. As.data.table is confusing if it doesn't have consistent behavior to data.table. <br>
<br>Thanks,<br>Rob<br><br><div class="gmail_quote">On Tue, May 25, 2010 at 3:46 AM, <span dir="ltr"><<a href="mailto:mdowle@mdowle.plus.com">mdowle@mdowle.plus.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Steve,<br>
<br>
Try data.table(df) rather than as.data.table(df). In the vignettes and<br>
examples I think data.table(df) is used but let us know otherwise.<br>
as.data.table() is a raw convert of the class only, currently.<br>
<br>
Agreed something needs to be tidied up here. Thanks for reporting it.<br>
<br>
All,<br>
<br>
Any preferences on the following options ? :<br>
<br>
1. Change as.data.table to use data.table. It already does when<br>
keep.rownames=TRUE but not when FALSE. If a user really wants a raw class<br>
change they can use class(x)="data.table" directly. No change to<br>
data.table or setkey. Since ?as.data.table is an alias to ?data.table<br>
this would be consistent.<br>
<br>
2. Change data.table and setkey. Only convert character to factor at the<br>
point of setkey. That may prevent radix being used for an ad hoc by on<br>
character columns that are not in the key. Would we then want to do<br>
auto-conversion in ad hoc by too? No change to as.data.table.<br>
<br>
3. Steve's suggestion. Change setkey. Catch character columns in setkey<br>
and auto convert them to factor at that point. No change to data.table or<br>
as.data.table.<br>
<br>
4. Change ?as.data.table to say its a class change only, and to use<br>
data.table() if checks and auto-conversion of character to factor is<br>
required. No code changes.<br>
<br>
5. Another solution.<br>
<br>
Any views? I currently lean towards option 1.<br>
<br>
Matthew<br>
<div><div></div><div class="h5"><br>
<br>
> Hi all,<br>
><br>
> Would it make sense to autoconvert characters to factors when setting<br>
> a character column as a key?<br>
><br>
> For example, when converting a data.frame to a data.table, picking a<br>
> character column as a key throws an error:<br>
><br>
> R> df <- data.frame(a=as.character(sample(LETTERS[1:10])), b=1:10,<br>
> stringsAsFactors=F)<br>
> R> dt <- as.data.table(df)<br>
> R> key(dt) <- 'a'<br>
> Error in setkey("x", value) :<br>
> All keyed columns must be storage mode integer<br>
><br>
> Converting dt$a to a factor before setting the key works fine, as<br>
> expected:<br>
><br>
> R> dt$a <- factor(dt$a)<br>
> R> key(dt) <- 'a'<br>
><br>
> So, I'm wondering if it would make sense to auto convert character<br>
> columns to factors when calling `key` on these columns ... maybe with<br>
> a warning, perhaps ... ?<br>
><br>
> Thanks,<br>
> -steve<br>
><br>
> --<br>
> Steve Lianoglou<br>
> Graduate Student: Computational Systems Biology<br>
> | Memorial Sloan-Kettering Cancer Center<br>
> | Weill Medical College of Cornell University<br>
> Contact Info: <a href="http://cbio.mskcc.org/%7Elianos/contact" target="_blank">http://cbio.mskcc.org/~lianos/contact</a><br>
> _______________________________________________<br>
> datatable-help mailing list<br>
> <a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
><br>
<br>
<br>
_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
</div></div></blockquote></div><br>