diff --git a/NEWS.md b/NEWS.md index c26a43e0b4..09f8965d99 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,7 +14,7 @@ 3. `fread(keepLeadingZeros=TRUE)` now correctly parses dates with components with leading zeros as dates instead of strings, [#6851](https://github.com/Rdatatable/data.table/issues/6851). Thanks @TurnaevEvgeny for the report and @ben-schwen for the fix. -4. `as.data.table()` now properly handles keys: specifying keys sets them, omitting keys preserves existing ones, and setting `key=NULL` clears them, [#6859](https://github.com/Rdatatable/data.table/issues/6859). Thanks @brookslogan for the report and @Mukulyadav2004 for the fix. +4. `as.data.table()` now properly handles keys: specifying keys sets them, omitting keys preserves existing ones, and setting `key=NULL` clears them. Additionally, `keep.rownames` is now consistently passed to `as.data.table(x, keep.rownames)`, [#6859](https://github.com/Rdatatable/data.table/issues/6859). Thanks @brookslogan for the report and @Mukulyadav2004 for the fix. 5. `as.data.table()` on `x` avoids an infinite loop if the output of the corresponding `as.data.frame()` method has the same class as the input, [#6874](https://github.com/Rdatatable/data.table/issues/6874). Concretely, we had `class(x) = c('foo', 'data.frame')` and `class(as.data.frame(x)) = c('foo', 'data.frame')`, so `as.data.frame.foo` wound up getting called repeatedly. Thanks @matschmitz for the report and @ben-schwen for the fix. diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index a61507a361..42e556bced 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -21105,6 +21105,10 @@ test(2309.06, key(as.data.table(DT, key="a")), "a") test(2309.07, key(as.data.table(DT)), NULL) test(2309.08, key(as.data.table(DT, key=NULL)), NULL) +# as.data.table(x, keep.rownames=TRUE) keeps rownames for class(x)==c("*", "data.frame") +df = structure(list(i = 1:2), class = c("tbl", "data.frame"), row.names = c("a","b")) +test(2309.09, as.data.table(df, keep.rownames=TRUE), data.table(rn = c("a","b"), i=1:2)) + # as.data.frame(x) does not reset class(x) to "data.frame" #6874 as.data.frame.no.reset = function(x) x DF = structure(list(a = 1:2), class = c("data.frame", "no.reset"), row.names = c(NA, -2L))