Skip to content

Develop#11

Merged
egenn merged 6 commits into
mainfrom
develop
Jul 3, 2026
Merged

Develop#11
egenn merged 6 commits into
mainfrom
develop

Conversation

@egenn

@egenn egenn commented Jul 3, 2026

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 3, 2026 05:13

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the package version to 0.4.1, removes the cli dependency, and replaces cli::cli_abort() and cli::cli_warn() calls with custom error and warning functions (abort(), warn(), info()) across several files. It also introduces a new internal utility function lighten() to lighten colors and updates plot.SupervisedSession.R to fetch colors dynamically from the rtemis namespace. Feedback on the changes suggests caching the rtemis namespace environment instead of repeatedly calling getFromNamespace(), ensuring that lighten() preserves the names of its input vector, and adding a unit test to verify this name preservation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 191 to 202
kind_colors <- c(
train = "#607D8B",
outer_fold = "#8E63CE",
tune = "#BE2E5F",
grid_cell = "#466D96",
train_alg = "#4F662A",
predict = "#6CA3A0",
varimp = "#F08904",
metrics = "#FDB808"
train = "#808080",
outer_fold = getFromNamespace("col_outer", "rtemis"),
tune = getFromNamespace("col_tuner", "rtemis"),
grid_cell = lighten(getFromNamespace("col_tuner", "rtemis"), 0.5),
preprocess = getFromNamespace("col_preprocessor", "rtemis"),
decompose = getFromNamespace("col_decom", "rtemis"),
train_alg = getFromNamespace("highlight_col", "rtemis"),
predict = rtemis.core::rtemis_colors[["blue"]],
varimp = rtemis.core::rtemis_colors[["light_blue"]],
metrics = rtemis.core::rtemis_colors[["orange"]]
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Repeatedly calling getFromNamespace() for multiple lookups in the same namespace is inefficient because each call performs package loading checks and environment lookups. Caching the namespace environment once using asNamespace("rtemis") and accessing the variables directly is much cleaner and more efficient.

  rtemis_ns <- asNamespace("rtemis")
  kind_colors <- c(
    train = "#808080",
    outer_fold = rtemis_ns$col_outer,
    tune = rtemis_ns$col_tuner,
    grid_cell = lighten(rtemis_ns$col_tuner, 0.5),
    preprocess = rtemis_ns$col_preprocessor,
    decompose = rtemis_ns$col_decom,
    train_alg = rtemis_ns$highlight_col,
    predict = rtemis.core::rtemis_colors[["blue"]],
    varimp = rtemis.core::rtemis_colors[["light_blue"]],
    metrics = rtemis.core::rtemis_colors[["orange"]]
  )

Comment thread r/R/utils.R
Comment on lines +465 to +496
lighten <- function(x, amount = 0.1) {
if (
!is.numeric(amount) ||
length(amount) != 1L ||
is.na(amount) ||
amount < 0 ||
amount > 1
) {
abort(
"`amount` must be a single numeric value in [0, 1].",
class = c("rtemis_value_error", "rtemis_input_error")
)
}
# Work in [0, 1]
rgba <- grDevices::col2rgb(x, alpha = TRUE) / 255
# Move each RGB channel `amount` of the way toward 1; leave alpha as is.
rgba[1:3, ] <- rgba[1:3, ] + (1 - rgba[1:3, ]) * amount
out <- character(ncol(rgba))
opaque <- rgba[4L, ] == 1
out[opaque] <- grDevices::rgb(
rgba[1L, opaque],
rgba[2L, opaque],
rgba[3L, opaque]
)
out[!opaque] <- grDevices::rgb(
rgba[1L, !opaque],
rgba[2L, !opaque],
rgba[3L, !opaque],
alpha = rgba[4L, !opaque]
)
out
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The lighten() function does not preserve the names of the input vector x because grDevices::rgb() drops them. In R, vector functions should generally preserve the names of their inputs to prevent breaking downstream code that relies on named vectors. This can be fixed by assigning names(x) to the output vector before returning it.

lighten <- function(x, amount = 0.1) {
  if (
    !is.numeric(amount) ||
      length(amount) != 1L ||
      is.na(amount) ||
      amount < 0 ||
      amount > 1
  ) {
    abort(
      "`amount` must be a single numeric value in [0, 1].",
      class = c("rtemis_value_error", "rtemis_input_error")
    )
  }
  # Work in [0, 1]
  rgba <- grDevices::col2rgb(x, alpha = TRUE) / 255
  # Move each RGB channel `amount` of the way toward 1; leave alpha as is.
  rgba[1:3, ] <- rgba[1:3, ] + (1 - rgba[1:3, ]) * amount
  out <- character(ncol(rgba))
  opaque <- rgba[4L, ] == 1
  out[opaque] <- grDevices::rgb(
    rgba[1L, opaque],
    rgba[2L, opaque],
    rgba[3L, opaque]
  )
  out[!opaque] <- grDevices::rgb(
    rgba[1L, !opaque],
    rgba[2L, !opaque],
    rgba[3L, !opaque],
    alpha = rgba[4L, !opaque]
  )
  names(out) <- names(x)
  out
}

Comment on lines +112 to +117
test_that("lighten accepts named colors and is vectorized", {
expect_equal(
rtemis.draw:::lighten(c("red", "#000000"), 0.5),
c("#FF8080", "#808080")
)
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Add a test case to verify that lighten() correctly preserves the names of the input vector.

test_that("lighten accepts named colors and is vectorized", {
  expect_equal(
    rtemis.draw:::lighten(c("red", "#000000"), 0.5),
    c("#FF8080", "#808080")
  )
  # Test name preservation
  expect_equal(
    rtemis.draw:::lighten(c(a = "#000000", b = "#FFFFFF"), 0.5),
    c(a = "#808080", b = "#FFFFFF")
  )
})

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates rtemis.draw away from {cli} condition helpers toward {rtemis.core}’s condition/message utilities, while also adding an internal lighten() helper to support consistent color derivations in plotting.

Changes:

  • Replaced many cli::cli_abort()/cli::cli_warn() calls with abort()/warn() (and added structured rtemis_* error classes).
  • Added internal lighten() utility and corresponding unit tests; updated plot(SupervisedSession) colors to use shared palette constants.
  • Updated tests to reflect the new condition classes and expected signaling behavior; bumped package version and rtemis.core minimum version.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
r/tests/testthat/test-utils.R Adds unit tests for new internal lighten() helper.
r/tests/testthat/test-network.R Updates expectation for static-export “not supported” signaling.
r/tests/testthat/test-map.R Updates expectation for static-export “not supported” signaling.
r/tests/testthat/test-draw_spectrogram.R Updates expected error classes for validation failures.
r/tests/testthat/test-draw_a3.R Updates expected error classes for validation failures.
r/R/utils.R Converts validation errors to abort() and introduces internal lighten().
r/R/plot.SupervisedSession.R Switches event kind palette to shared colors and uses lighten() for derived colors.
r/R/option.R Converts data_zoom validation error to abort().
r/R/network.R Converts warnings/errors to warn()/abort() and assigns rtemis_* classes.
r/R/map.R Converts warnings/errors to warn()/abort() and assigns rtemis_* classes.
r/R/draw.R Converts various argument validation errors to abort() with rtemis_* classes.
r/R/draw_spectrogram.R Converts validation errors and performance warnings to abort()/warn()/info().
r/R/draw_gantt.R Converts input validation errors to abort() with rtemis_* classes.
r/R/draw_a3.R Converts input validation errors to abort() with rtemis_* classes.
r/DESCRIPTION Bumps version/date, removes {cli} import, raises minimum {rtemis.core} version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread r/R/draw_spectrogram.R Outdated
Comment on lines 624 to 629
info(
"Consider reducing 'n_fft' (currently ",
n_fft,
")",
" or the signal length."
)
Comment thread r/R/map.R
@egenn egenn merged commit afd1b03 into main Jul 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants