Skip to content

Commit

Permalink
use insight helpers (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Mar 15, 2022
1 parent 1c9ca78 commit 599d25d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
6 changes: 3 additions & 3 deletions R/check_normality.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ check_normality.default <- function(x, ...) {
p.val <- .check_normality(stats::rstandard(x), x)

attr(p.val, "data") <- x
attr(p.val, "object_name") <- .safe_deparse(substitute(x))
attr(p.val, "object_name") <- insight::safe_deparse(substitute(x))
attr(p.val, "effects") <- "fixed"
class(p.val) <- unique(c("check_normality", "see_check_normality", class(p.val)))

Expand Down Expand Up @@ -149,7 +149,7 @@ check_normality.merMod <- function(x, effects = c("fixed", "random"), ...) {
}

attr(p.val, "data") <- x
attr(p.val, "object_name") <- .safe_deparse(substitute(x))
attr(p.val, "object_name") <- insight::safe_deparse(substitute(x))
attr(p.val, "effects") <- effects
class(p.val) <- unique(c("check_normality", "see_check_normality", class(p.val)))

Expand All @@ -171,7 +171,7 @@ check_normality.afex_aov <- function(x, ...) {
p.val <- .check_normality(r, x)

attr(p.val, "data") <- x
attr(p.val, "object_name") <- .safe_deparse(substitute(x))
attr(p.val, "object_name") <- insight::safe_deparse(substitute(x))
class(p.val) <- unique(c("check_normality", "see_check_normality", class(p.val)))

invisible(p.val)
Expand Down
2 changes: 1 addition & 1 deletion R/compare_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ compare_performance <- function(..., metrics = "all", rank = FALSE, estimator =
# iterate over all models, i.e. model-performance for each model
m <- mapply(function(.x, .y) {
dat <- model_performance(.x, metrics = metrics, estimator = estimator, verbose = FALSE)
model_name <- gsub("\"", "", .safe_deparse(.y), fixed = TRUE)
model_name <- gsub("\"", "", insight::safe_deparse(.y), fixed = TRUE)
perf_df <- data.frame(Name = model_name, Model = class(.x)[1], dat, stringsAsFactors = FALSE)
attributes(perf_df) <- c(attributes(perf_df), attributes(dat)[!names(attributes(dat)) %in% c("names", "row.names", "class")])
return(perf_df)
Expand Down
12 changes: 0 additions & 12 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# trim leading / trailing whitespaces
.trim <- function(x) gsub("^\\s+|\\s+$", "", x)


.get_BIC <- function(x, estimator = "ML") {
# check ML estimator
if (missing(estimator) && inherits(x, "lmerMod")) {
Expand All @@ -25,14 +21,6 @@
}




# safe deparse, works for very long strings
.safe_deparse <- function(string) {
paste0(sapply(deparse(string, width.cutoff = 500), .trim, simplify = TRUE), collapse = "")
}


.std <- function(x) {
if (!is.numeric(x)) {
return(x)
Expand Down
2 changes: 1 addition & 1 deletion R/icc.R
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ print.icc_decomposed <- function(x, digits = 2, ...) {
if (is.null(reform)) {
reform <- "all random effects"
} else {
reform <- .safe_deparse(reform)
reform <- insight::safe_deparse(reform)
}

cat(sprintf("Conditioned on: %s\n\n", reform))
Expand Down
4 changes: 2 additions & 2 deletions R/performance_roc.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ performance_roc <- function(x, ..., predictions, new_data) {
dots <- list(...)

object_names <- c(
.safe_deparse(substitute(x)),
sapply(match.call(expand.dots = FALSE)$`...`, .safe_deparse)
insight::safe_deparse(substitute(x)),
sapply(match.call(expand.dots = FALSE)$`...`, insight::safe_deparse)
)

if (insight::is_model(x)) {
Expand Down

0 comments on commit 599d25d

Please sign in to comment.