Skip to content

Commit

Permalink
closes #1681. as.data.table's data.table method returns a copy.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Apr 27, 2016
1 parent e9f1d1d commit 1c4231b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@

55. `fread()` did not respect encoding on header column. Now fixed, [#1680](https://github.com/Rdatatable/data.table/issues/1680). Thanks @nachti.

56. as.data.table's `data.table` method returns a copy as it should, [#1681](https://github.com/Rdatatable/data.table/issues/1681).

#### NOTES

1. Updated error message on invalid joins to reflect the new `on=` syntax, [#1368](https://github.com/Rdatatable/data.table/issues/1368). Thanks @MichaelChirico.
Expand Down
3 changes: 2 additions & 1 deletion R/as.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ as.data.table.data.frame <- function(x, keep.rownames=FALSE, ...) {
}

as.data.table.data.table <- function(x, ...) {
# as.data.table always returns a copy, automatically takes care of #473
x = copy(x) # #1681
# fix for #1078 and #1128, see .resetclass() for explanation.
setattr(x, 'class', .resetclass(x, "data.table"))
if (!selfrefok(x)) x = alloc.col(x) # fix for #473
return(x)
}
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -8830,6 +8830,12 @@ Encoding(x) = "latin1"
nm = names(fread("1680-fread-header-encoding.csv", encoding="Latin-1"))
test(1670, nm[2], x)

# as.data.table must return a copy even if 'x' is a data.table
x = data.table(a=1, b=2)
test(1670.1, address(x) != address(as.data.table(x)), TRUE)
setattr(x, 'class', c('a', class(x)))
test(1670.2, class(as.data.table(x)), class(x)[2:3])

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

# TODO: Tests involving GForce functions needs to be run with optimisation level 1 and 2, so that both functions are tested all the time.
Expand Down

0 comments on commit 1c4231b

Please sign in to comment.