diff --git a/Rlabkey/DESCRIPTION b/Rlabkey/DESCRIPTION index fe58ab1..b797163 100755 --- a/Rlabkey/DESCRIPTION +++ b/Rlabkey/DESCRIPTION @@ -20,4 +20,4 @@ Copyright: Copyright (c) 2010-2018 LabKey Corporation LazyLoad: true Depends: httr, jsonlite LinkingTo: Rcpp -Imports: Rcpp (>= 0.11.0) +Imports: Rcpp (>= 0.11.0), bit64 diff --git a/Rlabkey/R/makeDF.R b/Rlabkey/R/makeDF.R index 7be7a9c..ff6faef 100755 --- a/Rlabkey/R/makeDF.R +++ b/Rlabkey/R/makeDF.R @@ -14,6 +14,17 @@ # limitations under the License. ## +MAX_INT <- .Machine$integer.max +MIN_INT <- -MAX_INT - 1 +safe_as_integer64 <- function(x) { + x[x == ""] <- NA + if (any(x > MAX_INT | x < MIN_INT, na.rm = T)) { + return(bit64::as.integer64(x)) + } + + return(as.integer(x)) +} + makeDF <- function(rawdata, colSelect=NULL, showHidden, colNameOpt) { decode <- fromJSON(rawdata, simplifyVector=FALSE, simplifyDataFrame=FALSE) @@ -147,7 +158,7 @@ makeDF <- function(rawdata, colSelect=NULL, showHidden, colNameOpt) try( if(mod=="date") { newdat[,j] <- .parseDate(newdat[,j])} else if(mod=="string"){ suppressWarnings(mode(newdat[,j]) <- "character")} else - if(mod=="int"){ suppressWarnings(mode(newdat[,j]) <- "integer")} else + if(mod=="int"){ suppressWarnings(newdat[,j] <- safe_as_integer64(newdat[,j]))} else if(mod=="boolean"){suppressWarnings(mode(newdat[,j]) <- "logical")} else if(mod=="float"){suppressWarnings(mode(newdat[,j]) <- "numeric")} else {print("MetaData field type not recognized.")} @@ -163,7 +174,7 @@ makeDF <- function(rawdata, colSelect=NULL, showHidden, colNameOpt) try( if(mod=="date"){ newdat <- .parseDate(newdat)}else if(mod=="string"){suppressWarnings(mode(newdat) <- "character")} else - if(mod=="int"){ suppressWarnings(mode(newdat) <- "integer")} else + if(mod=="int"){ suppressWarnings(newdat[,j] <- safe_as_integer64(newdat[,j]))} else if(mod=="boolean"){suppressWarnings(mode(newdat) <- "logical")} else if(mod=="float"){suppressWarnings(mode(newdat) <- "numeric")} else {print("MetaData field type not recognized.")}