Skip to content

Commit

Permalink
default method for as.data.table, closes #969
Browse files Browse the repository at this point in the history
  • Loading branch information
jangorecki committed Jan 9, 2015
1 parent a18844e commit d09309f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -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

##########################


Expand Down

0 comments on commit d09309f

Please sign in to comment.