diff --git a/DESCRIPTION b/DESCRIPTION index 88c233cd..dc99bc9c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rtemis -Version: 0.99.1000 +Version: 0.99.1005 Title: Advanced Machine Learning and Visualization -Date: 2025-10-18 +Date: 2025-11-25 Authors@R: person(given = "E.D.", family = "Gennatas", role = c("aut", "cre"), email = "gennatas@gmail.com", comment = c(ORCID = "0000-0001-9280-3609")) Description: Advanced Machine Learning and Visualization for all. License: GPL (>= 3) diff --git a/NAMESPACE b/NAMESPACE index 2ce2a927..cb6d4319 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -138,6 +138,7 @@ export(plot_true_pred.Regression) export(plot_true_pred.RegressionRes) export(plot_varimp) export(preprocess) +export(preprocessed) export(present) export(present.list) export(previewcolor) @@ -149,6 +150,7 @@ export(recycle) export(regression_metrics) export(repr) export(repr_S7name) +export(repr_ls) export(resample) export(rnormmat) export(rt_reactable) @@ -187,7 +189,6 @@ export(setup_TabNet) export(setup_UMAP) export(setup_tSNE) export(sge_submit) -export(show_ls) export(size) export(sparsernorm) export(summarize) diff --git a/R/00_S7_init.R b/R/00_S7_init.R index da0a9283..165f75a9 100644 --- a/R/00_S7_init.R +++ b/R/00_S7_init.R @@ -5,6 +5,8 @@ # References # S7 generics: https://rconsortium.github.io/S7/articles/generics-methods.html +# --- Generics ------------------------------------------------------------------------------------- + #' String representation #' #' @details @@ -366,3 +368,14 @@ get_output_type <- function( match.arg(output_type) } # /rtemis::get_output_type + + +#' Get preprocessed data from Preprocessor +#' +#' @param x Preprocessor: A Preprocessor object. +#' @param ... Not used. +#' +#' @return data.frame: The preprocessed data. +#' +#' @export +preprocessed <- new_generic("preprocessed", "x") diff --git a/R/01_S7_Hyperparameters.R b/R/01_S7_Hyperparameters.R index 7c618cea..96a2cbba 100644 --- a/R/01_S7_Hyperparameters.R +++ b/R/01_S7_Hyperparameters.R @@ -23,7 +23,7 @@ TUNED_STATUS_TUNED <- 1L # `resampled` values ---- # 0: Running on single training set. -# 1: Running on cross-validated training sets. +# 1: Running on resampled training sets. #' @title Hyperparameters #' @@ -32,10 +32,11 @@ TUNED_STATUS_TUNED <- 1L #' #' @field algorithm Character: Algorithm name. #' @field hyperparameters Named list of algorithm hyperparameter values. -#' @field tuned Integer: Tuning status. -#' @field resampled Integer: Cross-validation status. #' @field tunable_hyperparameters Character: Names of tunable hyperparameters. #' @field fixed_hyperparameters Character: Names of fixed hyperparameters. +#' @field tuned Integer: Tuning status. +#' @field resampled Integer: Outer resampling status. +#' @field n_workers Integer: Number of workers to use for tuning. #' #' @author EDG #' @noRd @@ -140,7 +141,7 @@ method(repr, Hyperparameters) <- function( ) out <- paste0( out, - show_ls( + repr_ls( props(x)[-1], pad = pad, maxlength = maxlength, diff --git a/R/02_S7_Metrics.R b/R/02_S7_Metrics.R index 4ca7fd16..9f77f04d 100644 --- a/R/02_S7_Metrics.R +++ b/R/02_S7_Metrics.R @@ -87,7 +87,7 @@ method(repr, RegressionMetrics) <- function( } out <- paste0( out, - show_ls( + repr_ls( x@metrics, print_class = FALSE, print_df = TRUE, @@ -296,7 +296,7 @@ method(repr, MetricsRes) <- function( names(metricsl) <- names(x@mean_metrics) out <- paste0( out, - show_ls( + repr_ls( metricsl, print_class = FALSE, print_df = TRUE, diff --git a/R/03_S7_Preprocessor.R b/R/03_S7_Preprocessor.R index 49311aee..8871665a 100644 --- a/R/03_S7_Preprocessor.R +++ b/R/03_S7_Preprocessor.R @@ -90,7 +90,7 @@ method(repr, PreprocessorConfig) <- function( output_type <- get_output_type(output_type) paste0( repr_S7name("PreprocessorConfig", pad = pad, output_type = output_type), - show_ls(props(x), pad = pad, limit = limit, output_type = output_type) + repr_ls(props(x), pad = pad, limit = limit, output_type = output_type) ) } # /rtemis::show.PreprocessorConfig @@ -350,7 +350,7 @@ method(repr, Preprocessor) <- function( output_type <- get_output_type(output_type) out <- paste0( repr_S7name("Preprocessor", pad = pad, output_type = output_type), - show_ls(props(x), pad = pad, print_df = print_df) + repr_ls(props(x), pad = pad, print_df = print_df) ) } # /rtemis::show.Preprocessor @@ -385,3 +385,8 @@ method(`[`, Preprocessor) <- function(x, name) { method(`[[`, Preprocessor) <- function(x, name) { props(x)[[name]] } + +# preprocessed.Preprocessor ---- +method(preprocessed, Preprocessor) <- function(x) { + x@preprocessed +} diff --git a/R/05_S7_Tuner.R b/R/05_S7_Tuner.R index 75724516..ccda0bd2 100644 --- a/R/05_S7_Tuner.R +++ b/R/05_S7_Tuner.R @@ -340,7 +340,7 @@ method(repr, GridSearch) <- function( ) out <- paste( out, - show_ls(x@best_hyperparameters, output_type = output_type), + repr_ls(x@best_hyperparameters, output_type = output_type), sep = "" ) out diff --git a/R/06_S7_Supervised.R b/R/06_S7_Supervised.R index ed028f2a..1d4a859a 100644 --- a/R/06_S7_Supervised.R +++ b/R/06_S7_Supervised.R @@ -2,7 +2,7 @@ # ::rtemis:: # 2025 EDG rtemis.org -# Refs & Res +# References # https://github.com/RConsortium/S7/ # https://rconsortium.github.io/S7 # https://rconsortium.github.io/S7/articles/classes-objects.html?q=computed#computed-properties @@ -412,6 +412,7 @@ get_explain_fn <- function(algorithm) { paste0("explain_", algorithm) } + # Explain Supervised ---- #' Explain Supervised #' diff --git a/R/08_S7_ClusteringConfig.R b/R/08_S7_ClusteringConfig.R index 39b708f3..7560b705 100644 --- a/R/08_S7_ClusteringConfig.R +++ b/R/08_S7_ClusteringConfig.R @@ -53,7 +53,7 @@ method(repr, ClusteringConfig) <- function( ) paste0( out, - show_ls(props(x)[["config"]], pad = pad, output_type = output_type) + repr_ls(props(x)[["config"]], pad = pad, output_type = output_type) ) } # /show diff --git a/R/09_S7_Clustering.R b/R/09_S7_Clustering.R index 309a91ef..a89807a5 100644 --- a/R/09_S7_Clustering.R +++ b/R/09_S7_Clustering.R @@ -57,7 +57,7 @@ method(repr, Clustering) <- function( output_type <- get_output_type(output_type) paste0( repr_S7name(paste(x$algorithm, "Clustering")), - show_ls(props(x)[-1], pad = pad, output_type = output_type) + repr_ls(props(x)[-1], pad = pad, output_type = output_type) ) } # /rtemis::show.Clustering diff --git a/R/10_S7_DecompositionConfig.R b/R/10_S7_DecompositionConfig.R index 1bcf64ef..835be379 100644 --- a/R/10_S7_DecompositionConfig.R +++ b/R/10_S7_DecompositionConfig.R @@ -65,7 +65,7 @@ method(repr, DecompositionConfig) <- function( pad = pad, output_type = output_type ), - show_ls(x["config"], pad = pad, limit = -1L, output_type = output_type) + repr_ls(x["config"], pad = pad, limit = -1L, output_type = output_type) ) } # /rtemis::show.DecompositionConfig diff --git a/R/11_S7_Decomposition.R b/R/11_S7_Decomposition.R index 28c035fe..2fa08fc5 100644 --- a/R/11_S7_Decomposition.R +++ b/R/11_S7_Decomposition.R @@ -63,7 +63,7 @@ method(repr, Decomposition) <- function( pad = pad, output_type = output_type ), - show_ls(props(x)[-1], pad = pad, output_type = output_type) + repr_ls(props(x)[-1], pad = pad, output_type = output_type) ) } # /rtemis::show.Decomposition diff --git a/R/14_S7_utils.R b/R/14_S7_utils.R index b0b1c0e4..1144991c 100644 --- a/R/14_S7_utils.R +++ b/R/14_S7_utils.R @@ -401,7 +401,7 @@ print.CheckData <- function( } else { out <- paste( out, - bold(green(" * Everything looks good")), + highlight(" * Everything looks good"), sep = "\n" ) } diff --git a/R/fmt.R b/R/fmt.R index cf26c8be..6691a89f 100644 --- a/R/fmt.R +++ b/R/fmt.R @@ -50,11 +50,12 @@ fmt <- function( thin = FALSE, muted = FALSE, bg = NULL, + pad = 0L, output_type = c("ansi", "html", "plain") ) { output_type <- match.arg(output_type) - switch( + out <- switch( output_type, "ansi" = { codes <- character() @@ -157,7 +158,11 @@ fmt <- function( } }, "plain" = x - ) + ) # /switch + if (pad > 0L) { + out <- paste0(strrep(" ", pad), out) + } + out } # /rtemis::fmt @@ -166,6 +171,7 @@ fmt <- function( #' A `fmt()` convenience wrapper for highlighting text. #' #' @param x Character: Text to highlight. +#' @param pad Integer: Number of spaces to pad before text. #' @param output_type Character: Output type ("ansi", "html", "plain"). #' #' @return Character: Formatted text with highlight. @@ -175,9 +181,10 @@ fmt <- function( #' @keywords internal highlight <- function( x, + pad = 0L, output_type = c("ansi", "html", "plain") ) { - fmt(x, col = highlight_col, bold = TRUE, output_type = output_type) + fmt(x, col = highlight_col, bold = TRUE, pad = pad, output_type = output_type) } # /rtemis::highlight highlight2 <- function( @@ -282,7 +289,7 @@ muted <- function(x, output_type = c("ansi", "html", "plain")) { #' @keywords internal #' @noRd gray <- function(x, output_type = c("ansi", "html", "plain")) { - fmt(x, col = "gray", output_type = output_type) + fmt(x, col = "#808080", output_type = output_type) } # /rtemis::gray diff --git a/R/msg.R b/R/msg.R index 83d42373..cfb69f45 100644 --- a/R/msg.R +++ b/R/msg.R @@ -19,7 +19,7 @@ datetime <- function(datetime_format = "%Y-%m-%d %H:%M:%S") { #' @noRd # Used by msg(), msg0(), msgstart() msgdatetime <- function(datetime_format = "%Y-%m-%d %H:%M:%S") { - message(gray(paste0(datetime(), gray(" "))), appendLF = FALSE) + message(gray(paste0(datetime(), " ")), appendLF = FALSE) } diff --git a/R/read.R b/R/read.R index 50aa0cdd..978cdffb 100644 --- a/R/read.R +++ b/R/read.R @@ -102,7 +102,7 @@ read <- function( check_dependencies("arrow") if (verbosity > 0L) { msg0( - bold(green("\u25B6")), + highlight("\u25B6"), " Reading ", highlight(basename(path)), " using arrow::read_parquet()..." @@ -113,7 +113,7 @@ read <- function( } else if (ext == "rds") { if (verbosity > 0L) { msg0( - bold(green("\u25B6")), + bold(highlight("\u25B6")), " Reading ", highlight(basename(path)), "..." @@ -124,7 +124,7 @@ read <- function( check_dependencies("openxlsx") if (verbosity > 0L) { msg0( - bold(green("\u25B6")), + bold(highlight("\u25B6")), " Reading ", highlight(basename(path)), " using readxl::read_excel()..." @@ -141,7 +141,7 @@ read <- function( check_dependencies("haven") if (verbosity > 0L) { msg0( - bold(green("\u25B6")), + bold(highlight("\u25B6")), " Reading ", highlight(basename(path)), " using haven::read_dta()..." @@ -153,7 +153,7 @@ read <- function( check_dependencies("seqinr") if (verbosity > 0L) { msg0( - bold(green("\u25B6")), + bold(highlight("\u25B6")), " Reading ", highlight(basename(path)), " using seqinr::read.fasta()..." @@ -169,7 +169,7 @@ read <- function( check_dependencies("farff") if (verbosity > 0L) { msg0( - bold(green("\u25B6")), + bold(highlight("\u25B6")), " Reading ", highlight(basename(path)), " using farff::readARFF()..." @@ -180,7 +180,7 @@ read <- function( } else { if (verbosity > 0L) { msg0( - bold(green("\u25B6")), + bold(highlight("\u25B6")), " Reading ", highlight(basename(path)), " using ", @@ -332,7 +332,7 @@ msgread <- function(x, caller = "", use_basename = TRUE) { x <- basename(x) } msg0( - bold(green("\u25B6")), + bold(highlight("\u25B6")), " Reading ", highlight(x), "...", diff --git a/R/rtemis_color_system.R b/R/rtemis_color_system.R index c60e950a..436b99d3 100644 --- a/R/rtemis_color_system.R +++ b/R/rtemis_color_system.R @@ -44,8 +44,8 @@ rt_teal <- rtemis_teal rt_purple <- rtemis_purple rt_magenta <- rtemis_magenta -col_object <- rt_teal highlight_col <- rt_teal +col_object <- rt_teal col_info <- highlight2_col <- lmd_burgundy col_outer <- rt_red col_tuner <- rt_orange # genlib orange diff --git a/R/train_GLMNET.R b/R/train_GLMNET.R index 49c36185..966a2676 100644 --- a/R/train_GLMNET.R +++ b/R/train_GLMNET.R @@ -201,17 +201,21 @@ explain_GLMNET <- function(model, x, dat_training, method = NULL) { if (!method %in% c("shapr")) { cli::cli_abort("Explain method for GLMNET must be 'shapr'") } - newdata <- as.matrix( - model.matrix(~., dat_training)[, -1, drop = FALSE] - ) + x_mat <- model.matrix(~., x)[, -1, drop = FALSE] + dat_training_mat <- model.matrix(~., dat_training)[, -1, drop = FALSE] if (method == "shapr") { + phi0 <- if (model@type == "Classification") { + mean(model@predicted_prob_training) + } else { + mean(model@predicted_training) + } shapr::explain( model = model@model, - x_explain = x, - x_train = dat_training, + x_explain = x_mat, + x_train = dat_training_mat, predict_model = predict_GLMNET, approach = "ctree", - phi0 = mean(model@predicted_training) + phi0 = phi0 ) } } # /rtemis::explain_GLMNET diff --git a/R/utils_art.R b/R/utils_art.R index c959417a..e0167ff8 100644 --- a/R/utils_art.R +++ b/R/utils_art.R @@ -308,7 +308,7 @@ show_col <- function( if (limit != -1L && length(x) > limit) { limit_text <- paste0( italic( - thin( + gray( paste0( "Showing first ", limit, @@ -330,7 +330,7 @@ show_col <- function( if (limit != -1L && counter > limit) { more_text <- paste0( italic( - thin( + gray( paste0( "...", length(x) - limit, diff --git a/R/utils_data.table.R b/R/utils_data.table.R index 1e313d51..49e854c3 100644 --- a/R/utils_data.table.R +++ b/R/utils_data.table.R @@ -163,7 +163,7 @@ dt_merge <- function( ) if (left_on == right_on) { msg0( - bold(green(icon)), + bold(highlight(icon)), " Merging ", highlight(left_name), " & ", @@ -174,7 +174,7 @@ dt_merge <- function( ) } else { msg0( - bold(green(icon)), + bold(highlight(icon)), " Merging ", highlight(left_name), " & ", @@ -597,7 +597,7 @@ dt_names_by_class <- function( } else { sapply(vals, \(i) names(x)[classes == i]) } - cat(show_ls(out, item_format = item_format, maxlength = maxlength)) + cat(repr_ls(out, item_format = item_format, maxlength = maxlength)) invisible() } # /rtemis::dt_names_by_class diff --git a/R/utils_duckdb.R b/R/utils_duckdb.R index 8d26d634..fef2c8e0 100644 --- a/R/utils_duckdb.R +++ b/R/utils_duckdb.R @@ -81,14 +81,14 @@ ddb_data <- function( fileext <- tools::file_ext(path) out <- paste( - bold(green("\u25B6")), + bold(highlight("\u25B6")), ifelse(collect, "Reading", "Lazy-reading"), highlight(basename(path)) ) if (!is.null(filter_column)) { out <- paste( out, - bold(green("\u29e8")), + bold(highlight("\u29e8")), "filtering on", bold(filter_column) ) diff --git a/R/utils_print.R b/R/utils_print.R index feed1559..9ac4a392 100644 --- a/R/utils_print.R +++ b/R/utils_print.R @@ -121,7 +121,7 @@ printls <- function( # Print each item up to limit items if (limit != -1L && length(x) > limit) { padcat( - italic(thin( + italic(gray( paste( "Showing first", limit, @@ -137,7 +137,7 @@ printls <- function( counter <- counter + 1L if (limit != -1L && counter > limit) { padcat( - italic(thin( + italic(gray( paste0( "...", length(x) - limit, @@ -645,7 +645,7 @@ pastels <- function(x, bullet = " -") { #' Get first few elements of a vector with ellipsis #' #' @details -#' Used, for example, by `show_ls` +#' Used, for example, by `repr_ls` #' #' @return Character. #' @@ -867,20 +867,6 @@ list2html <- function( } # /rtemis::list2html -#' @author EDG -#' @keywords internal -#' @noRd -printchar <- function(x, left_pad = 2) { - target_length <- left_pad + max(nchar(x)) - for (i in x) { - cat( - highlight(leftpad(i, target_length)), - "\n" - ) - } -} # /rtemis::printchar - - # Helper function to build padded string equivalent of padcat show_padded <- function( text, @@ -904,7 +890,7 @@ show_padded <- function( #' Show list as formatted string #' #' Works exactly like printls, but instead of printing to console with cat, -#' it outputs a single string, formatted using mformat, so that cat(show_ls(x)) +#' it outputs a single string, formatted using mformat, so that cat(repr_ls(x)) #' looks identical to printls(x) for any list x #' #' @param x list or object that will be converted to a list. @@ -934,7 +920,7 @@ show_padded <- function( #' @keywords internal #' @export -show_ls <- function( +repr_ls <- function( x, prefix = "", pad = 2L, @@ -1022,7 +1008,7 @@ show_ls <- function( if (limit != -1L && length(x) > limit) { limit_text <- paste0( italic( - thin( + gray( paste0( "Showing first ", limit, @@ -1043,7 +1029,7 @@ show_ls <- function( if (limit != -1L && counter > limit) { more_text <- paste0( italic( - thin( + gray( paste0( "...", length(x) - limit, @@ -1089,7 +1075,7 @@ show_ls <- function( result <- paste0(result, item_text) if (is_common_struct(x[[i]])) { - sub_result <- show_ls( + sub_result <- repr_ls( x[[i]], pad = lhs + 2, item_format = item_format, @@ -1277,4 +1263,4 @@ show_ls <- function( } result -} # /rtemis::show_ls +} # /rtemis::repr_ls diff --git a/R/utils_strings.R b/R/utils_strings.R index 5fabb8a6..be57dce4 100644 --- a/R/utils_strings.R +++ b/R/utils_strings.R @@ -230,15 +230,6 @@ clean_colnames <- function(x) { } -leftpad <- function(x, target_length, pad_char = " ") { - lpad <- target_length - nchar(x) - if (lpad > 0) { - paste0(paste0(rep(pad_char, lpad), collapse = ""), x) - } else { - x - } -} - #' Force plain text when using `message()` #' #' @param x Character: Text to be output to console. @@ -312,9 +303,9 @@ pastebox <- function(x, pad = 0) { #' Show S7 class name #' #' @param x Character: S7 class name. -#' @param colors Character: Color codes for the object name. +#' @param col Color: Color code for the object name. #' @param pad Integer: Number of spaces to pad the message with. -#' @param verbosity Integer: Verbosity level. If > 1, adds package name to the output. +#' @param prefix Character: Prefix to add to the object name. #' @param output_type Character: Output type ("ansi", "html", "plain"). #' #' @return Character: Formatted string that can be printed with cat(). @@ -324,27 +315,25 @@ pastebox <- function(x, pad = 0) { #' @keywords internal repr_S7name <- function( x, - colors = c(rtemis_teal, rtemis_light_teal), + col = col_object, pad = 0L, - verbosity = 2L, + prefix = NULL, output_type = NULL ) { output_type <- get_output_type(output_type) paste0( strrep(" ", pad), - gray(if (verbosity > 1L) "", output_type = output_type), "\n" ) } # /rtemis::repr_S7name + #' Cat object #' #' @param x Character: Object description @@ -363,21 +352,22 @@ objcat <- function( x, col = col_object, pad = 0L, - verbosity = 2L, + prefix = NULL, output_type = c("ansi", "html", "plain") ) { output_type <- match.arg(output_type) out <- repr_S7name( x, - colors = col, + col = col, pad = pad, - verbosity = verbosity, + prefix = prefix, output_type = output_type ) cat(out) } # rtemis::objcat + #' Function to label #' #' Create axis label from function definition and variable name diff --git a/man/fmt.Rd b/man/fmt.Rd index 153cbf4b..6a9ba51b 100644 --- a/man/fmt.Rd +++ b/man/fmt.Rd @@ -13,6 +13,7 @@ fmt( thin = FALSE, muted = FALSE, bg = NULL, + pad = 0L, output_type = c("ansi", "html", "plain") ) } diff --git a/man/highlight.Rd b/man/highlight.Rd index cc015d79..d2c988fb 100644 --- a/man/highlight.Rd +++ b/man/highlight.Rd @@ -4,11 +4,13 @@ \alias{highlight} \title{Highlight text} \usage{ -highlight(x, output_type = c("ansi", "html", "plain")) +highlight(x, pad = 0L, output_type = c("ansi", "html", "plain")) } \arguments{ \item{x}{Character: Text to highlight.} +\item{pad}{Integer: Number of spaces to pad before text.} + \item{output_type}{Character: Output type ("ansi", "html", "plain").} } \value{ diff --git a/man/preprocessed.Rd b/man/preprocessed.Rd new file mode 100644 index 00000000..d213ce06 --- /dev/null +++ b/man/preprocessed.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/00_S7_init.R +\name{preprocessed} +\alias{preprocessed} +\title{Get preprocessed data from Preprocessor} +\usage{ +preprocessed(x, ...) +} +\arguments{ +\item{x}{Preprocessor: A Preprocessor object.} + +\item{...}{Not used.} +} +\value{ +data.frame: The preprocessed data. +} +\description{ +Get preprocessed data from Preprocessor +} diff --git a/man/repr_S7name.Rd b/man/repr_S7name.Rd index 5cb65f69..f402a9f2 100644 --- a/man/repr_S7name.Rd +++ b/man/repr_S7name.Rd @@ -4,22 +4,16 @@ \alias{repr_S7name} \title{Show S7 class name} \usage{ -repr_S7name( - x, - colors = c(rtemis_teal, rtemis_light_teal), - pad = 0L, - verbosity = 2L, - output_type = NULL -) +repr_S7name(x, col = col_object, pad = 0L, prefix = NULL, output_type = NULL) } \arguments{ \item{x}{Character: S7 class name.} -\item{colors}{Character: Color codes for the object name.} +\item{col}{Color: Color code for the object name.} \item{pad}{Integer: Number of spaces to pad the message with.} -\item{verbosity}{Integer: Verbosity level. If > 1, adds package name to the output.} +\item{prefix}{Character: Prefix to add to the object name.} \item{output_type}{Character: Output type ("ansi", "html", "plain").} } diff --git a/man/show_ls.Rd b/man/repr_ls.Rd similarity index 97% rename from man/show_ls.Rd rename to man/repr_ls.Rd index f08c67b5..4ce90002 100644 --- a/man/show_ls.Rd +++ b/man/repr_ls.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils_print.R -\name{show_ls} -\alias{show_ls} +\name{repr_ls} +\alias{repr_ls} \title{Show list as formatted string} \usage{ -show_ls( +repr_ls( x, prefix = "", pad = 2L, @@ -61,7 +61,7 @@ Character: Formatted string that can be printed with cat() } \description{ Works exactly like printls, but instead of printing to console with cat, -it outputs a single string, formatted using mformat, so that cat(show_ls(x)) +it outputs a single string, formatted using mformat, so that cat(repr_ls(x)) looks identical to printls(x) for any list x } \details{ diff --git a/tests/testthat/test_explain.R b/tests/testthat/test_explain.R index bec20440..677661d7 100644 --- a/tests/testthat/test_explain.R +++ b/tests/testthat/test_explain.R @@ -4,6 +4,10 @@ # Test individual-level explanations +# library(data.table) +# library(rtemis) +# library(testthat) + # Data ---- ## Regression Data ---- n <- 400 @@ -39,7 +43,7 @@ ex_r_glmnet <- explain( dat_training = features(datr_train) ) -test_that("explain() on GLMNET succeeds", { +test_that("explain() on GLMNET Regression succeeds", { expect_s3_class(ex_r_glmnet, "shapr") }) @@ -52,6 +56,16 @@ mod_c_glmnet <- train( hyperparameters = setup_GLMNET(lambda = 0.01) ) +ex_c_glmnet <- explain( + model = mod_c_glmnet, + x = features(datc2_test[1, ]), + dat_training = features(datc2_train) +) + +test_that("explain() on GLMNET Classification succeeds", { + expect_s3_class(ex_c_glmnet, "shapr") +}) + ## LightRF Regression ---- mod_r_lightrf <- train( x = datr_train, @@ -64,6 +78,6 @@ ex_r_lightrf <- explain( model = mod_r_lightrf, x = features(datr_test[1, ]) ) -test_that("explain() on LightRF succeeds", { +test_that("explain() on LightRF Regression succeeds", { expect_true(is.list(ex_r_lightrf)) }) diff --git a/tests/testthat/test_strings.R b/tests/testthat/test_strings.R index 5baeb25f..c4f1b79e 100644 --- a/tests/testthat/test_strings.R +++ b/tests/testthat/test_strings.R @@ -26,14 +26,14 @@ test_that("fmt_gradient() works", { expect_true(is.character(out)) }) -# show_ls ---- +# repr_ls ---- x <- list( a = 1:5, b = letters[1:5], c = rnorm(5) ) -out <- show_ls(x, title = "Test List") -test_that("show_ls() works", { +out <- repr_ls(x, title = "Test List") +test_that("repr_ls() works", { expect_true(is.character(out)) }) @@ -53,10 +53,10 @@ x <- list( l = setup_LightCART() ) -# show_ls(x, limit = 5L) |> cat() -# show_ls(x, limit = -1L) |> cat() +# repr_ls(x, limit = 5L) |> cat() +# repr_ls(x, limit = -1L) |> cat() -test_that("show_ls() handles long lists", { - expect_true(is.character(show_ls(x, limit = 5L))) - expect_true(is.character(show_ls(x, limit = -1L))) +test_that("repr_ls() handles long lists", { + expect_true(is.character(repr_ls(x, limit = 5L))) + expect_true(is.character(repr_ls(x, limit = -1L))) })