From d09309fe6932d8a0a2bc8861d96e0fd68237a00c Mon Sep 17 00:00:00 2001 From: jangorecki Date: Fri, 9 Jan 2015 22:43:15 +0100 Subject: [PATCH] default method for as.data.table, closes #969 --- NAMESPACE | 1 + R/data.table.R | 4 ++++ inst/tests/tests.Rraw | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 25dfbd98e..57472a5bf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -44,6 +44,7 @@ S3method(as.data.table, ordered) S3method(as.data.table, Date) S3method(as.data.table, table) S3method(as.data.table, xts) +S3method(as.data.table, default) S3method(as.data.frame, data.table) S3method(as.list, data.table) S3method(as.matrix, data.table) diff --git a/R/data.table.R b/R/data.table.R index e514d5287..864e97bc6 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1843,6 +1843,10 @@ as.data.table <-function(x, keep.rownames=FALSE) UseMethod("as.data.table") } +as.data.table.default <- function(x, ...){ + setDT(as.data.frame(x, ...))[] +} + as.data.frame.data.table <- function(x, ...) { ans = copy(x) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 1a570e1ef..94fa331db 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -5741,6 +5741,12 @@ if ("package:xts" %in% search()) { test(1465.4, xt, xt_dt) } +# as.data.table.default #969 +ar <- array(NA, dim=c(10,4),dimnames = list(NULL,paste0("col",1:4))) +test(1466.1, as.data.table(as.data.frame(ar)), as.data.table(ar)) # array type +x <- rep(Sys.time(),3) +test(1466.2, as.data.table(as.data.frame(x)), as.data.table(x)) # posix type + ##########################