From e9e6ba49888115fad06de606e82fa0ee013e412d Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 22 Jul 2022 08:46:23 +0200 Subject: [PATCH] Use internal copy of to_numeric Since it will be removed from datawizard: https://github.com/easystats/datawizard/issues/197#issuecomment-1191460271 modelbased needs to be updated on CRAN before datawizard. --- R/estimate_grouplevel.R | 2 +- R/utils.R | 8 ++++++++ R/visualisation_recipe.estimate_grouplevel.R | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 R/utils.R diff --git a/R/estimate_grouplevel.R b/R/estimate_grouplevel.R index e3790e283..be9f49598 100644 --- a/R/estimate_grouplevel.R +++ b/R/estimate_grouplevel.R @@ -83,7 +83,7 @@ estimate_grouplevel <- function(model, type = "random", ...) { random <- random[c("Group", "Level", names(random)[!names(random) %in% c("Group", "Level")])] # Sort - random <- random[order(random$Group, datawizard::to_numeric(random$Level), random$Parameter), ] + random <- random[order(random$Group, .to_numeric(random$Level), random$Parameter), ] # Clean row.names(random) <- NULL diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 000000000..16219323f --- /dev/null +++ b/R/utils.R @@ -0,0 +1,8 @@ +#' @keywords internal +#' @noRd +.to_numeric <- function(x) { + tryCatch(as.numeric(as.character(x)), + error = function(e) x, + warning = function(w) x + ) +} diff --git a/R/visualisation_recipe.estimate_grouplevel.R b/R/visualisation_recipe.estimate_grouplevel.R index 0132c4424..b1f72acbf 100644 --- a/R/visualisation_recipe.estimate_grouplevel.R +++ b/R/visualisation_recipe.estimate_grouplevel.R @@ -38,7 +38,7 @@ visualisation_recipe.estimate_grouplevel <- function(x, ...) { data <- as.data.frame(x) # Fix order so that it's plotted with sorted levels - data$Level <- factor(data$Level, levels = sort(datawizard::to_numeric(unique(data$Level)))) + data$Level <- factor(data$Level, levels = sort(.to_numeric(unique(data$Level)))) layers <- list()