Skip to content

Conversation

@dfkapraun
Copy link
Collaborator

Updates that allow one to work with two different models simultaneously in the same R session. In previous versions of the package, attempting this could cause problems because a single set of C function and variable names (e.g., "initParms" and "Outputs") were used for all models that were created and loaded in a single R session. I've now updated the package so that all C function and object names are model-specific.

@dfkapraun dfkapraun requested a review from Copilot November 25, 2025 20:53
Copy link
Contributor

Copilot AI left a comment

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 enables multiple different MCSim models to be used simultaneously within the same R session by implementing model-specific naming for C functions and variables. Previously, all models shared common names (e.g., "initParms", "derivs"), causing conflicts when multiple models were loaded.

Key Changes:

  • Modified compilation process to append model names to C function and variable names
  • Updated model initialization to dynamically assign model-specific functions
  • Fixed a spelling error in documentation

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
DESCRIPTION Updated version to 1.1.9000 for development
R/compileModel.R Added logic to rename C and R objects with model-specific suffixes during compilation
R/MCSim_model.R Modified model initialization to use dynamic assignment of model-specific functions
man/Model-class.Rd Corrected spelling of "initial" in documentation

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

Comment on lines +118 to +120
r_command_string <- paste0("initStates <<- initStates_", mName)
r_expression <- parse(text = r_command_string)
eval(r_expression)
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

The pattern of building strings, parsing, and evaluating is repeated three times. Consider extracting this into a helper function to reduce duplication and improve maintainability. For example: assign_model_function <- function(name, mName) { eval(parse(text = paste0(name, ' <<- ', name, '_', mName))) }

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +126
r_command_string <- paste0("Outputs <<- Outputs_", mName)
r_expression <- parse(text = r_command_string)
eval(r_expression)
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

The pattern of building strings, parsing, and evaluating is repeated three times. Consider extracting this into a helper function to reduce duplication and improve maintainability. For example: assign_model_function <- function(name, mName) { eval(parse(text = paste0(name, ' <<- ', name, '_', mName))) }

Copilot uses AI. Check for mistakes.
@dfkapraun dfkapraun merged commit 30073a5 into main Nov 25, 2025
3 checks passed
@dfkapraun dfkapraun deleted the multimodel branch November 25, 2025 20:59
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