diff --git a/NEWS.md b/NEWS.md index 61a9c596b..f11c73269 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,8 @@ ``` When you see the `..` prefix think _one-level-up_ like the directory `..` in all operating systems meaning the parent directory. In future the `..` prefix could be made to work on all symbols apearing anywhere inside `DT[...]`. It is intended to be a convenient way to protect your code from accidentally picking up a column name. Similar to how `x.` and `i.` prefixes (analogous to SQL table aliases) can already be used to disambiguate the same column name present in both `x` and `i`. A symbol prefix rather than a `..()` _function_ will be easier for us to optimize internally and more convenient if you have many variables in calling scope that you wish to use in your expressions safely. This feature was first raised in 2012 and long wished for, [#633](https://github.com/Rdatatable/data.table/issues/633). It is experimental. +3. When `fread()` or `print()` see `integer64` columns are present, `bit64`'s namespace is now automatically loaded for convenience. + #### BUG FIXES 1. Some long-standing potential instability has been discovered and resolved many thanks to a detailed report from Bill Dunlap and Michael Sannella. At C level any call of the form `setAttrib(x, install(), allocVector())` can be unstable in any R package. Despite `setAttrib()` PROTECTing its inputs, the 3rd argument (`allocVector`) can be executed first only for its result to to be released by install()'s potential GC before reaching `setAttrib`'s PROTECTion of its inputs. Fixed by either PROTECTing or pre-install()ing. Added to CRAN_Release.cmd procedures: i) `grep`s to prevent usage of this idiom in future and ii) running data.table's test suite with `gctorture(TRUE)`. diff --git a/R/data.table.R b/R/data.table.R index d436622d6..f4554934a 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -72,10 +72,7 @@ print.data.table <- function(x, topn=getOption("datatable.print.topn"), printdots = FALSE } toprint=format.data.table(toprint, ...) - # fix for #975. - if (any(sapply(x, function(col) "integer64" %in% class(col))) && !"package:bit64" %in% search()) { - warning("Some columns have been read as type 'integer64' but package bit64 isn't loaded. Those columns will display as strange looking floating point data. There is no need to reload the data. Just require(bit64) to obtain the integer64 print method and print the data again.") - } + if (!isNamespaceLoaded("bit64") && any(sapply(x,inherits,"integer64"))) require_bit64() # FR #5020 - add row.names = logical argument to print.data.table if (isTRUE(row.names)) rownames(toprint)=paste(format(rn,right=TRUE,scientific=FALSE),":",sep="") else rownames(toprint)=rep.int("", nrow(toprint)) if (is.null(names(x)) | all(names(x) == "")) colnames(toprint)=rep("", ncol(toprint)) # fixes bug #97 (RF#4934) and #545 (RF#5253) diff --git a/R/fread.R b/R/fread.R index 8efb633a5..2ec5748ff 100644 --- a/R/fread.R +++ b/R/fread.R @@ -99,8 +99,7 @@ fread <- function(input="",sep="auto",sep2="auto",nrows=-1L,header="auto",na.str if (is.atomic(colClasses) && !is.null(names(colClasses))) colClasses = tapply(names(colClasses),colClasses,c,simplify=FALSE) # named vector handling ans = .Call(Creadfile,input,sep,as.integer(nrows),header,na.strings,verbose,as.integer(autostart),skip,select,drop,colClasses,integer64,dec,encoding,quote,strip.white,blank.lines.skip,fill,showProgress) nr = length(ans[[1]]) - if ( integer64=="integer64" && !exists("print.integer64") && any(sapply(ans,inherits,"integer64")) ) - warning("Some columns have been read as type 'integer64' but package bit64 isn't loaded. Those columns will display as strange looking floating point data. There is no need to reload the data. Just require(bit64) to obtain the integer64 print method and print the data again.") + if (!isNamespaceLoaded("bit64") && any(sapply(ans,inherits,"integer64"))) require_bit64() setattr(ans,"row.names",.set_row_names(nr)) if (isTRUE(data.table)) { diff --git a/R/utils.R b/R/utils.R index 0e4cbbd9c..07af702a5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -47,3 +47,12 @@ UseMethod("%+%") "%+%.default" <- function(x,y) paste(paste(x,collapse=","),paste(y,collapse=","),sep="") # we often construct warning msgs with a msg followed by several items of a vector, so %+% is for convenience + +require_bit64 = function() { + # called in fread and print when they see integer64 columns are present + tt = try(requireNamespace("bit64",quietly=TRUE)) + if (inherits(tt,"try-error")) + warning("Some columns are type 'integer64' but package bit64 is not installed. Those columns will print as strange looking floating point data. There is no need to reload the data. Simply install.packages('bit64') to obtain the integer64 print method and print the data again.") +} + +