diff --git a/NEWS.md b/NEWS.md index 596a01f7d6..63bf10d094 100644 --- a/NEWS.md +++ b/NEWS.md @@ -86,6 +86,8 @@ 14. Filling columns of class Date with POSIXct (and vice versa) using `shift()` now yields a clear, informative error message specifying the class mismatch, [#5218](https://github.com/Rdatatable/data.table/issues/5218). Thanks @ashbaldry for the report and @ben-schwen for the fix. +15. `dim.data.table` returns now the same as `dim.data.frame` in `data.table`-unaware environments, [#2422](https://github.com/Rdatatable/data.table/issues/2422). Thanks to @akersting for reporting and Benjamin Schwendinger for the fix. + ### NOTES 1. The following in-progress deprecations have proceeded: diff --git a/R/cedta.R b/R/cedta.R index 6c99bea302..4528578298 100644 --- a/R/cedta.R +++ b/R/cedta.R @@ -48,7 +48,7 @@ cedta.pkgEvalsUserCode = c("gWidgetsWWW","statET","FastRWeb","slidify","rmarkdow } # cedta = Calling Environment Data.Table-Aware -cedta = function(n=2L) { +cedta = function(n=2L, verbose = getOption("datatable.verbose", FALSE)) { # Calling Environment Data Table Aware env = parent.frame(n) if (isTRUEorFALSE(env$.datatable.aware)) { # dtplyr#184, #5654 @@ -72,7 +72,7 @@ cedta = function(n=2L) { (nsname %chin% cedta.pkgEvalsUserCode && .any_eval_calls_in_stack()) || isTRUE(ns$.datatable.aware) || # As of Sep 2018: RCAS, caretEnsemble, dtplyr, rstanarm, rbokeh, CEMiTool, rqdatatable, RImmPort, BPRMeth, rlist tryCatch("data.table" %chin% get(".Depends",paste("package",nsname,sep=":"),inherits=FALSE),error=function(e)FALSE) # both ns$.Depends and get(.Depends,ns) are not sufficient - if (!ans && getOption("datatable.verbose")) { + if (!ans && verbose) { # nocov start catf("cedta decided '%s' wasn't data.table aware. Here is call stack with [[1L]] applied:\n", nsname) print(sapply(sys.calls(), `[[`, 1L)) diff --git a/R/data.table.R b/R/data.table.R index 5702558409..198f8b0d89 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1,5 +1,6 @@ dim.data.table = function(x) { + if (!cedta(verbose=FALSE)) return(NextMethod()) # nocov .Call(Cdim, x) } diff --git a/R/print.data.table.R b/R/print.data.table.R index 1504b32341..03e0fe3f8f 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -72,7 +72,7 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), setnames(index_dt, print_names) } } - n_x = nrow(x) + n_x = dim(x)[1L] # manually dispatch nrow() to avoid dispatching to S3 method if ((topn*2L+1L)nrows || !topnmiss)) { toprint = rbindlist(list(head(x, topn), tail(x, topn)), use.names=FALSE) # no need to match names because head and tail of same x, and #3306 rn = c(seq_len(topn), seq.int(to=n_x, length.out=topn))