Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", comment = c(ORCID = "0000-0001-9280-3609"))
Description: Advanced Machine Learning and Visualization for all.
License: GPL (>= 3)
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -149,6 +150,7 @@ export(recycle)
export(regression_metrics)
export(repr)
export(repr_S7name)
export(repr_ls)
export(resample)
export(rnormmat)
export(rt_reactable)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions R/00_S7_init.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# References
# S7 generics: https://rconsortium.github.io/S7/articles/generics-methods.html

# --- Generics -------------------------------------------------------------------------------------

#' String representation
#'
#' @details
Expand Down Expand Up @@ -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")
9 changes: 5 additions & 4 deletions R/01_S7_Hyperparameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -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
Expand Down Expand Up @@ -140,7 +141,7 @@ method(repr, Hyperparameters) <- function(
)
out <- paste0(
out,
show_ls(
repr_ls(
props(x)[-1],
pad = pad,
maxlength = maxlength,
Expand Down
4 changes: 2 additions & 2 deletions R/02_S7_Metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ method(repr, RegressionMetrics) <- function(
}
out <- paste0(
out,
show_ls(
repr_ls(
x@metrics,
print_class = FALSE,
print_df = TRUE,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions R/03_S7_Preprocessor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Comment on lines +390 to +392
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new preprocessed() generic function and its method for Preprocessor objects lack test coverage. Since other methods in the same file have comprehensive test coverage in tests/testthat/test_Preprocessor.R, consider adding a test case to verify that preprocessed(x) correctly returns the preprocessed data from a Preprocessor object.

Copilot uses AI. Check for mistakes.
2 changes: 1 addition & 1 deletion R/05_S7_Tuner.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion R/06_S7_Supervised.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -412,6 +412,7 @@ get_explain_fn <- function(algorithm) {
paste0("explain_", algorithm)
}


# Explain Supervised ----
#' Explain Supervised
#'
Expand Down
2 changes: 1 addition & 1 deletion R/08_S7_ClusteringConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/09_S7_Clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/10_S7_DecompositionConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/11_S7_Decomposition.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/14_S7_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ print.CheckData <- function(
} else {
out <- paste(
out,
bold(green(" * Everything looks good")),
highlight(" * Everything looks good"),
sep = "\n"
)
}
Expand Down
15 changes: 11 additions & 4 deletions R/fmt.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -157,7 +158,11 @@ fmt <- function(
}
},
"plain" = x
)
) # /switch
if (pad > 0L) {
out <- paste0(strrep(" ", pad), out)
}
out
} # /rtemis::fmt


Expand All @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion R/msg.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down
16 changes: 8 additions & 8 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()..."
Expand All @@ -113,7 +113,7 @@ read <- function(
} else if (ext == "rds") {
if (verbosity > 0L) {
msg0(
bold(green("\u25B6")),
bold(highlight("\u25B6")),
" Reading ",
highlight(basename(path)),
"..."
Expand All @@ -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()..."
Expand All @@ -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()..."
Expand All @@ -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()..."
Expand All @@ -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()..."
Expand All @@ -180,7 +180,7 @@ read <- function(
} else {
if (verbosity > 0L) {
msg0(
bold(green("\u25B6")),
bold(highlight("\u25B6")),
" Reading ",
highlight(basename(path)),
" using ",
Expand Down Expand Up @@ -332,7 +332,7 @@ msgread <- function(x, caller = "", use_basename = TRUE) {
x <- basename(x)
}
msg0(
bold(green("\u25B6")),
bold(highlight("\u25B6")),
" Reading ",
highlight(x),
"...",
Expand Down
2 changes: 1 addition & 1 deletion R/rtemis_color_system.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 10 additions & 6 deletions R/train_GLMNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions R/utils_art.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ show_col <- function(
if (limit != -1L && length(x) > limit) {
limit_text <- paste0(
italic(
thin(
gray(
paste0(
"Showing first ",
limit,
Expand All @@ -330,7 +330,7 @@ show_col <- function(
if (limit != -1L && counter > limit) {
more_text <- paste0(
italic(
thin(
gray(
paste0(
"...",
length(x) - limit,
Expand Down
Loading