Skip to content

Conversation

Copy link

Copilot AI commented Dec 26, 2025

Add which_mcnode functions to identify nodes with specific conditions

Changes Made (addressing all PR feedback):

  • Renamed mcmodule_nas() to which_mcnode_na()
  • Created generic which_mcnode() function for custom conditions
  • Added which_mcnode_inf() to detect infinite values
  • Organized all functions in which_mcnode.R file
  • Updated documentation to start with "Identifies..." instead of "This function"
  • Replaced \dontrun with actual runnable examples
  • Simplified examples and tests to use mcdata() directly for creating mcnodes with NA/Inf values
  • Updated NAMESPACE with new exports
  • Created comprehensive tests (40 test cases)

New Functions:

  1. which_mcnode(mcmodule, test_func) - Generic function to find nodes matching any condition
  2. which_mcnode_na(mcmodule) - Finds nodes containing NA values
  3. which_mcnode_inf(mcmodule) - Finds nodes containing Inf or -Inf values

Files Changed:

  • Deleted: R/mcmodule_nas.R, tests/testthat/test-mcmodule_nas.R, man/mcmodule_nas.Rd
  • Added: R/which_mcnode.R, tests/testthat/test-which_mcnode.R
  • Added: man/which_mcnode.Rd, man/which_mcnode_na.Rd, man/which_mcnode_inf.Rd
  • Modified: NAMESPACE

Testing:

✅ Examples use mcdata() directly for simple mcnode creation
✅ Tests use mcdata() to create mcnodes with specific values (NA, Inf, etc.)
✅ Follows package conventions while being more straightforward than using mcstoc(runif, ...)

Original prompt

This section details on the original issue you should resolve

<issue_title>Add mcmodule errors/NA inspection function</issue_title>
<issue_description>Something like this that can help find mcnodes in a big mcmodule causing trouble

#' Find mcnodes in a mcmodule that contain NAs
#' 
#' @param mcmodule
#'
#' @return names of the mcnodes containing NAs
#' 
#' @examples
#' mcmodule_nas(intro)


mcmodule_nas<-function(mcmodule){
  
  node_names<-names(mcmodule$node_list)
  
  mcnodes_na<-sapply(mcmodule$node_list[node_names], "[[", "mcnode")
  mcnodes_na<-sapply(mcnodes_na, "is.na")
  mcnodes_na<-sapply(mcnodes_na, "any")
  
  return(names(mcnodes_na[mcnodes_na]))

}

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits December 26, 2025 11:42
Co-authored-by: NataliaCiria <114077263+NataliaCiria@users.noreply.github.com>
Co-authored-by: NataliaCiria <114077263+NataliaCiria@users.noreply.github.com>
Co-authored-by: NataliaCiria <114077263+NataliaCiria@users.noreply.github.com>
…sMessages

Co-authored-by: NataliaCiria <114077263+NataliaCiria@users.noreply.github.com>
Copilot AI changed the title [WIP] Add mcmodule errors/NA inspection function Add mcmodule_nas() to identify nodes containing NA values Dec 26, 2025
Copilot AI requested a review from NataliaCiria December 26, 2025 11:50
@codecov-commenter
Copy link

codecov-commenter commented Dec 26, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@NataliaCiria NataliaCiria changed the base branch from main to v1.2.0 December 26, 2025 11:54
Copy link
Owner

@NataliaCiria NataliaCiria left a comment

Choose a reason for hiding this comment

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

I want the function to be named "which_mcnode_na()". Additionally, include an equivalent function that checks for inf and -inf values "which_mcnode_inf()". They could be organized in a file called which_mcnode.R and include first a generic which_mcnode() that allows to "sapply" a function through mcmodules that return mcnode names, (for example, which mcnodes are negative), and then use that function to create the NAs and Inf wrappers.

R/mcmodule_nas.R Outdated
Comment on lines 3 to 5
#' This function identifies which mcnodes within an mcmodule contain NA values.
#' This is useful for troubleshooting and debugging Monte Carlo models to find
#' nodes that may be causing issues due to missing or undefined values.
Copy link
Owner

Choose a reason for hiding this comment

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

Remove "This funtion" start with "Identifies..."

Copy link
Author

Choose a reason for hiding this comment

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

Updated documentation to start with "Identifies..." in commit 485cfbc

R/mcmodule_nas.R Outdated
Comment on lines 12 to 16
#' @examples
#' \dontrun{
#' # Find nodes with NAs in the imports_mcmodule
#' mcmodule_nas(imports_mcmodule)
#' }
Copy link
Owner

Choose a reason for hiding this comment

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

Write an actual example, do not use \dontrun

Copy link
Author

Choose a reason for hiding this comment

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

Replaced \dontrun with actual runnable examples in commit 485cfbc. Examples now demonstrate usage with imports_mcmodule and show how to create test mcmodules.

…de_na, add which_mcnode_inf and generic which_mcnode

Co-authored-by: NataliaCiria <114077263+NataliaCiria@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 26, 2025

I want the function to be named "which_mcnode_na()". Additionally, include an equivalent function that checks for inf and -inf values "which_mcnode_inf()". They could be organized in a file called whi...

Completed all requested changes in commit 485cfbc:

  • Renamed function to which_mcnode_na()
  • Added which_mcnode_inf() for checking infinite values
  • Created generic which_mcnode() function that accepts custom test functions
  • Organized all functions in which_mcnode.R file
  • All 40 tests passing

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: NataliaCiria <114077263+NataliaCiria@users.noreply.github.com>
Copilot AI changed the title Add mcmodule_nas() to identify nodes containing NA values Add which_mcnode functions to identify nodes with specific conditions Dec 26, 2025
Copilot AI requested a review from NataliaCiria December 26, 2025 12:12
Copy link
Owner

@NataliaCiria NataliaCiria left a comment

Choose a reason for hiding this comment

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

The functions look good, but mcnodes in the examples and tests must be created with mcdata() or mcstoc(), they are not vectors or matrices. Check other tests in the package.

…ode creation

Co-authored-by: NataliaCiria <114077263+NataliaCiria@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 26, 2025

The functions look good, but mcnodes in the examples and tests must be created with mcdata() or mcstoc(), they are not vectors or matrices. Check other tests in the package.

Updated all examples and tests to use mcdata() and mcstoc() for proper mcnode creation in commit 5e464f8. Examples now follow the same pattern as other functions in the package (e.g., mcnode_na_rm).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: NataliaCiria <114077263+NataliaCiria@users.noreply.github.com>
Copilot AI requested a review from NataliaCiria December 26, 2025 12:29
@NataliaCiria NataliaCiria marked this pull request as ready for review December 26, 2025 12:32
@NataliaCiria NataliaCiria merged commit 6cbc8f3 into v1.2.0 Dec 26, 2025
7 checks passed
@NataliaCiria NataliaCiria deleted the copilot/add-mcmodule-na-inspection branch December 26, 2025 12:34
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.

Add mcmodule errors/NA inspection function

3 participants