Skip to content

fix simulation_results names#122

Open
dlefaudeux wants to merge 8 commits into
mainfrom
fix-simulation-results-names
Open

fix simulation_results names#122
dlefaudeux wants to merge 8 commits into
mainfrom
fix-simulation-results-names

Conversation

@dlefaudeux

@dlefaudeux dlefaudeux commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

closes #121

Summary by CodeRabbit

  • Bug Fixes
    • Simulation result lists and tables now preserve and display original simulation names so returned results match user-created names.
  • Chores / UX Improvements
    • Activation/bootstrap now suppresses noisy startup output when configured, more robustly installs from cache, improves cache path detection, tightens version checks, and warns (without crashing) on bootstrap failures.
  • Documentation
    • Regenerated and reformatted several help pages and package metadata; updated doc anchors and roxygen configuration.

@coderabbitai

coderabbitai Bot commented Apr 1, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Two unrelated changes: R/snapshot.R remaps filesystem-safe simulation names back to the original snapshot simulation names for stored results and tibbles. renv/activate.R applies multiple bootstrap/activation refinements (version/checksum bump, suppressed startup output, safer cache bootstrap copy, repo parsing refactor, cache-path inference, stricter version equality, and tryCatch-wrapped bootstrap run).

Changes

Snapshot simulation-name remapping

Layer / File(s) Summary
Build reverse name map & use for outputs
R/snapshot.R
Create original_sim_names by applying the same substitution used to derive sim_names from filenames. Use original_sim_names[sim_names] for list keys and original_name <- unname(original_sim_names[sim_name]) inside the loop so both stored SimulationResults objects and produced tibbles are keyed by the original snapshot simulation names.

renv activation and bootstrap changes

Layer / File(s) Summary
Bootstrap target bump & checksum
renv/activate.R
Update embedded bootstrap target version and md5 checksum constants.
Startup output suppression
renv/activate.R
Add early-return/suppression in catf() controlled by RENV_CONFIG_STARTUP_QUIET and RENV_CONFIG_SYNCHRONIZED_CHECK.
Bootstrap-from-cache copy safety
renv/activate.R
Ensure destination library directory exists before file.copy() and only treat bootstrap-from-cache as successful if the recursive copy succeeds.
Repository override parsing
renv/activate.R
Refactor parsing of renv.repos.cran semicolon-delimited overrides into a named repo map while preserving single-unnamed→CRAN behavior.
Cache path inference
renv/activate.R
When RENV_PATHS_CACHE is empty, consult RENV_PATHS_ROOT and derive a root/cache path if present.
Release version equality check
renv/activate.R
Change release version validation to use identical(c(expected), c(version)) for comparison.
Bootstrap run error handling
renv/activate.R
Wrap renv_bootstrap_run_impl() with tryCatch in renv_bootstrap_run(), issuing a warning (not rethrowing) that suggests running renv::activate() if bootstrapping fails.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: fixing how simulation_results names are handled to match original simulation names.
Linked Issues check ✅ Passed The PR implementation correctly remaps simulation_results names to original simulation names by building an original_sim_names mapping and using it for results assignment, directly addressing issue #121's requirement.
Out of Scope Changes check ✅ Passed Most changes are documentation updates (man/ files, DESCRIPTION, renv/activate.R). The core fix in R/snapshot.R is in-scope; renv changes appear to be dependency updates; other changes are ancillary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-simulation-results-names

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@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 modifies the result naming logic in R/snapshot.R to map sanitized file names back to their original simulation names, specifically handling cases where slashes were replaced by underscores. The review identifies a critical logic error where the subsequent loop uses sanitized names to index into the result lists, which will now fail to match the updated original names and cause incorrect list assignments. Additionally, the feedback suggests that the mapping logic should be more robust to account for other characters that might be sanitized beyond just slashes.

Comment thread R/snapshot.R
Comment thread R/snapshot.R Outdated
# sim_names correspond to the original simulations names but if it contains "/" it has been replaced by "_"
# create mapping to ensure returned list name correspond to the original simulation names
original_sim_names <- self$get_names("simulations")
names(original_sim_names) <- gsub("/", "_", original_sim_names)

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 mapping logic specifically targets slashes. If simulation names contain other characters that are sanitized by the underlying tool (e.g., spaces, dots, or other special characters), this gsub will not account for them, leading to NA names in the results list. It would be safer to use a more comprehensive sanitization or to verify if other characters are also replaced.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
R/snapshot.R (1)

409-423: ⚠️ Potential issue | 🔴 Critical

Name remapping is bypassed during result assignment, creating two separate sets of keys

At Line 409, you pre-name results_obj and results_tibble with original simulation names (e.g., "Sim/1", "Sim/2"), but Lines 417 and 421 assign using filesystem-safe sim_name (e.g., "Sim_1", "Sim_2"). In R, x[[name]] <- value creates a new element if the name doesn't exist in the list. This means your lists end up with both the original-named slots (empty) and sanitized-named slots (populated). Downstream code at lines 585, 597, 612 accesses by original names, which will fail.

Proposed fix
       results_obj <- results_tibble <- vector("list", length(sim_results_files))
       names(results_obj) <- names(results_tibble) <- original_sim_names[sim_names]

       for (i in seq_along(sim_results_files)) {
         sim_name <- sim_names[i]
+        result_name <- unname(original_sim_names[sim_name])
+        if (is.na(result_name)) {
+          cli::cli_abort(
+            "Unable to map simulation result file name {.code {sim_name}} back to an original simulation name."
+          )
+        }
         simulation <- ospsuite::loadSimulation(file.path(
           temp_dir,
           glue(temp_file_name, "-", sim_name, ".pkml")
         ))
-        results_obj[[sim_name]] <- ospsuite::importResultsFromCSV(
+        results_obj[[result_name]] <- ospsuite::importResultsFromCSV(
           simulation,
           file.path(temp_dir, sim_results_files[i])
         )
-        results_tibble[[
-          sim_name
-        ]] <- ospsuite::simulationResultsToTibble(results_obj[[sim_name]])
+        results_tibble[[result_name]] <-
+          ospsuite::simulationResultsToTibble(results_obj[[result_name]])
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@R/snapshot.R` around lines 409 - 423, You pre-set names using
original_sim_names[sim_names] but then assign using the filesystem-safe
sim_name, creating duplicate keys; change the assignments to use the original
name mapping instead (e.g., compute target_name <- original_sim_names[sim_name]
or original_sim_names[sim_names[i]] and then do results_obj[[target_name]] <-
ospsuite::importResultsFromCSV(...) and results_tibble[[target_name]] <-
ospsuite::simulationResultsToTibble(...)) so the populated list slots match the
pre-named keys (references: results_obj, results_tibble, original_sim_names,
sim_names, sim_name, importResultsFromCSV, simulationResultsToTibble).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@R/snapshot.R`:
- Around line 406-407: The gsub("/", "_", ...) mapping for
names(original_sim_names) can produce duplicate keys; replace that single
assignment with a guarded sequence: create safe_names <- gsub("/", "_",
original_sim_names), check for duplicated(safe_names) and if any duplicates
exist call safe_names <- make.unique(safe_names, sep = "_") (or append numeric
suffixes) and optionally emit a warning, then set names(original_sim_names) <-
safe_names so the mapping is injective and collisions are avoided.

---

Outside diff comments:
In `@R/snapshot.R`:
- Around line 409-423: You pre-set names using original_sim_names[sim_names] but
then assign using the filesystem-safe sim_name, creating duplicate keys; change
the assignments to use the original name mapping instead (e.g., compute
target_name <- original_sim_names[sim_name] or original_sim_names[sim_names[i]]
and then do results_obj[[target_name]] <- ospsuite::importResultsFromCSV(...)
and results_tibble[[target_name]] <- ospsuite::simulationResultsToTibble(...))
so the populated list slots match the pre-named keys (references: results_obj,
results_tibble, original_sim_names, sim_names, sim_name, importResultsFromCSV,
simulationResultsToTibble).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ae683ab-eca8-441d-801b-b52e7dc59028

📥 Commits

Reviewing files that changed from the base of the PR and between f546a91 and 06ba1f5.

📒 Files selected for processing (1)
  • R/snapshot.R

Comment thread R/snapshot.R Outdated
@dlefaudeux
dlefaudeux requested a review from nautilus69 April 3, 2026 07:27

@nautilus69 nautilus69 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

additional note: RCMDcheck failure is not related to this change.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@renv/activate.R`:
- Line 1059: The comparison uses redundant c() coercion: replace the expression
that checks package versions so it directly compares the two character strings
(variables expected and version) without wrapping them in c(); update the
condition from the current is.character(expected) && identical(c(expected),
c(version)) to a simpler is.character(expected) && identical(expected, version)
(or add is.character(version) if you want explicit type-safety) in
renv/activate.R where expected is derived from description[["Version"]] and
version is the installed version.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b541929e-68a9-4de1-b420-cb0fad643823

📥 Commits

Reviewing files that changed from the base of the PR and between 640471f and fbe8339.

⛔ Files ignored due to path filters (1)
  • renv.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • renv/activate.R

Comment thread renv/activate.R
renv_bootstrap_validate_version_release <- function(version, description) {
expected <- description[["Version"]]
is.character(expected) && identical(expected, version)
is.character(expected) && identical(c(expected), c(version))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for related version comparison patterns and the types involved
rg -n -C3 "renv_bootstrap_validate_version_release" --type=r

# Check if there are tests or documentation about version types
rg -n "numeric_version|package_version" --type=r -g "renv/activate.R"

Repository: esqLABS/cts

Length of output: 838


🏁 Script executed:

# Look at the calling context at line 1016
rg -n -B 15 "renv_bootstrap_validate_version_release" renv/activate.R | head -40

# Check where version comes from in the bootstrap flow
rg -n "function(version" renv/activate.R

# Look for how version objects are created/handled
rg -n -C 3 "as\.character.*version|c\(.*version" renv/activate.R

Repository: esqLABS/cts

Length of output: 2655


🏁 Script executed:

# Find where version is passed to the bootstrap chain
rg -n "renv_bootstrap_exec\|renv_bootstrap_validate_version" renv/activate.R | head -20

# Look at the whole bootstrap flow to see where version comes from
rg -n -B 5 -A 5 "renv_bootstrap_exec.*version" renv/activate.R

# Check if numeric_version is applied to the version parameter
rg -n "numeric_version" renv/activate.R

Repository: esqLABS/cts

Length of output: 804


🏁 Script executed:

# Look at lines around 1434 to find version origin
sed -n '1400,1440p' renv/activate.R | cat -n

# Also search for where version is first defined in the activate.R file
rg -n "^version <-|^  version <-" renv/activate.R | head -10

Repository: esqLABS/cts

Length of output: 1440


🏁 Script executed:

# Find where version is assigned (likely in the main body)
rg -n "version.*<-.*\"" renv/activate.R

# Look for the main function body - search around line 1395
sed -n '1370,1410p' renv/activate.R | cat -n

# Also check if version is used with numeric_version anywhere in the validation path
rg -n -B 3 -A 3 "numeric_version.*version|version.*numeric_version" renv/activate.R

Repository: esqLABS/cts

Length of output: 1825


🏁 Script executed:

# Check how description is created - via packageDescription
rg -n "packageDescription" renv/activate.R -B 2 -A 2

# Look for any tests or edge cases around version validation
rg -n "test.*version|describe.*version" renv/activate.R -i

# Check git log for this specific change (if available)
git log -p --all -S "identical(c(expected), c(version))" -- renv/activate.R 2>/dev/null | head -50

Repository: esqLABS/cts

Length of output: 814


🏁 Script executed:

# Search for any place where version might be transformed to numeric_version
rg -n "as\..*version|numeric_version|package_version" renv/activate.R | grep -v "^943:"

# Look specifically in the validation functions
sed -n '1001,1070p' renv/activate.R | cat -n

Repository: esqLABS/cts

Length of output: 2986


Simplify the version comparison to remove redundant c() coercion.

Both expected (from description[["Version"]]) and version are character strings and do not require wrapping in c() before comparison. The coercion is a no-op for character inputs and suggests uncertainty about the parameter types. Simplify to is.character(expected) && identical(expected, version) for clarity. If type safety is needed, add an explicit is.character(version) check instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@renv/activate.R` at line 1059, The comparison uses redundant c() coercion:
replace the expression that checks package versions so it directly compares the
two character strings (variables expected and version) without wrapping them in
c(); update the condition from the current is.character(expected) &&
identical(c(expected), c(version)) to a simpler is.character(expected) &&
identical(expected, version) (or add is.character(version) if you want explicit
type-safety) in renv/activate.R where expected is derived from
description[["Version"]] and version is the installed version.

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.

If simulation name contains a "/" is it replace by "_" in simulation_results names, which prevent direct matching

2 participants