Skip to content

Update function parsing to handle externalptr and add unlistable fallback#344

Merged
bburns632 merged 8 commits intomainfrom
jyq-externalptr-error
Feb 24, 2026
Merged

Update function parsing to handle externalptr and add unlistable fallback#344
bburns632 merged 8 commits intomainfrom
jyq-externalptr-error

Conversation

@jayqi
Copy link
Collaborator

@jayqi jayqi commented Feb 20, 2026

Make .parse_function more robust and fix error from externalptr.

  • Refactor listable check into .is_listable_expr and add check for externalptr type
  • Refactor as.list(x) into .try_as_list with fallback and logging a warning

Closes #343

TODO:

  • Test on FIMS
  • Add unit tests

@jayqi jayqi changed the title Add check for externalptr; add tryCatch on as.list Update function parsing to handle externalptr and add fallback Feb 20, 2026
@jayqi jayqi changed the title Update function parsing to handle externalptr and add fallback Update function parsing to handle externalptr and add unlistable fallback Feb 20, 2026
@jayqi jayqi marked this pull request as ready for review February 24, 2026 03:34
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 pull request addresses issue #343 where FunctionReporter would fail with an error when analyzing packages that use Rcpp, due to the presence of externalptr type expressions that cannot be converted to lists. The fix makes expression parsing more robust by:

  1. Extracting the "listable" check into a dedicated .is_listable_expr() function that explicitly handles external pointers
  2. Creating a .try_as_list() wrapper that gracefully handles as.list() failures with logging
  3. Updating both .parse_function() and .parse_R6_expression() to use these new utilities

Changes:

  • Refactored listable expression checking into .is_listable_expr() with explicit handling for externalptr types
  • Added .try_as_list() function with error handling and fallback behavior
  • Updated .parse_function() and .parse_R6_expression() to use the new helper functions
  • Added comprehensive unit tests for the new behavior
  • Updated NEWS.md with bugfix entry

Reviewed changes

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

File Description
R/FunctionReporter.R Added .is_listable_expr() and .try_as_list() helper functions; refactored .parse_function() and .parse_R6_expression() to use these helpers for robust expression parsing
tests/testthat/test-FunctionReporter-class.R Added tests for external pointer handling and fallback behavior when as.list() fails
NEWS.md Added bugfix entry documenting the fix for externalptr runtime error

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

jayqi and others added 3 commits February 23, 2026 23:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

Thanks, yep I support this approach.

If you found that this is doing what you want on #343, I'm good with it.

Copy link
Collaborator

@bburns632 bburns632 left a comment

Choose a reason for hiding this comment

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

LGTM

@bburns632 bburns632 merged commit c293ca0 into main Feb 24, 2026
6 checks passed
@bburns632 bburns632 deleted the jyq-externalptr-error branch February 24, 2026 04:56
@kellijohnson-NOAA
Copy link

Brilliant and so fast 🚀 . Thank you!

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.

Inability to run graph_viz when package uses Rcpp

5 participants