From 9d81223a4c4f5cf9dccfad91b8d4f4a0959bc838 Mon Sep 17 00:00:00 2001 From: danschrage Date: Sun, 3 May 2020 13:52:27 -0700 Subject: [PATCH 1/2] Make drop_redundant_dims safe for data.table --- R/misc.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/misc.R b/R/misc.R index 126bcea3e..99ef79640 100644 --- a/R/misc.R +++ b/R/misc.R @@ -743,6 +743,9 @@ check_stanfit <- function(x) { # otherwise if_missing is returned. # drop_redundant_dims <- function(data) { + if(inherits(data, "data.table")) { + return(data) + } drop_dim <- sapply(data, function(v) is.matrix(v) && NCOL(v) == 1) data[, drop_dim] <- lapply(data[, drop_dim, drop=FALSE], drop) return(data) From a53ec598e7344d68bf8749a05a964760cd8d1498 Mon Sep 17 00:00:00 2001 From: danschrage Date: Mon, 4 May 2020 09:49:52 -0700 Subject: [PATCH 2/2] Make drop_redundant_dims safe for data.table Instead of checking for data.table in `drop_redundant_dims`, follow the behavior of `validate_newdata` and coerce everything to a data.frame in `validate_data` before calling `drop_redundant_dims`. --- R/misc.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/misc.R b/R/misc.R index 99ef79640..db52ffefb 100644 --- a/R/misc.R +++ b/R/misc.R @@ -743,9 +743,6 @@ check_stanfit <- function(x) { # otherwise if_missing is returned. # drop_redundant_dims <- function(data) { - if(inherits(data, "data.table")) { - return(data) - } drop_dim <- sapply(data, function(v) is.matrix(v) && NCOL(v) == 1) data[, drop_dim] <- lapply(data[, drop_dim, drop=FALSE], drop) return(data) @@ -759,6 +756,9 @@ validate_data <- function(data, if_missing = NULL) { stop("'data' must be a data frame.", call. = FALSE) } + # drop other classes (e.g. 'tbl_df', 'tbl', 'data.table') + data <- as.data.frame(data) + drop_redundant_dims(data) }