Skip to content

FunctionReporter fails on Rcpp C++Function objects with externalptr in function body #348

Description

@awilnoaa

Description

pkgnet::FunctionReporter fails when analyzing a package that exposes Rcpp/module-backed functions with class C++Function. In this case, the package is FIMS.

The package report is partly generated, but the function dependency visualization fails with:

Error in as.vector(x, "list") : 
  cannot coerce type 'externalptr' to vector of type 'list'

Expected Behavior

I was trying to build the function dependency network using FunctionReporter. I thought maybe it would skip or parse around Rcpp external pointer objects or produce maybe an error message explaining that C++Function, Rcpp module functions, or externalptr objects listed are unsupported.

I checked the FunctionReporter documentation. It lists limitations for NSE, list-stored functions, R6/reference object methods, and reference class methods, but I did not see Rcpp C++Function / externalptr function bodies mentioned. If these are intentionally outside scope, would it be possible for FunctionReporter to skip them or fail with a more informative message?

Actual behavior

The HTML report renders the Function Network section header, but the visualization fails.

The same failure can be reproduced outside the HTML report:

library(pkgnet)

fr <- pkgnet::FunctionReporter$new()
fr$set_package("FIMS")

fr$nodes
fr$edges
traceback()

Output:

INFO [...] Extracting functions from FIMS as graph nodes...
INFO [...] FIMS ... done extracting functions as nodes.
INFO [...] Extracting dependencies between functions in FIMS as graph edges...
Error in as.vector(x, "list") : 
  cannot coerce type 'externalptr' to vector of type 'list'

The traceback shows the failure occurs inside pkgnet’s recursive function parser:

17: as.list.default(x)
16: as.list(x)
...
6: .parse_function(f)
5: FUN(X[[i]], ...)
4: lapply(X = funs, FUN = .called_by, all_functions = funs, pkg_env = pkg_env)
3: data.table::rbindlist(...)
2: private$extract_edges()
1: fr$edges

Diagnostic Detail

In this package, 22 of 130 function nodes are C++Function objects. Parsing those function bodies with pkgnet’s internal parser produces the same error:

# Example failing objects include:
c(
  "CreateTMBModel",
  "clear",
  "get_fixed",
  "get_log",
  "get_parameter_names",
  "get_random",
  "init_logging",
  "logit",
  "set_fixed",
  "set_random",
  "write_log"
)

Their bodies contain .External(...) calls with pointer objects. Excluding C++Function objects as source functions allows edge extraction for the remaining R functions to succeed:

total_function_nodes = 130
r_function_nodes = 108
cpp_function_nodes = 22
edges_from_r_functions = 141

Environment
OS: Windows 11 x64, build 26200
R version: 4.5.1
pkgnet version: 0.6.0
FIMS version: 0.9.4

I’m happy to provide more diagnostics if helpful. Thank you for your consideration.

Activity

  1. jameslamb commented on Aug 11, 2026

    @jameslamb
    Collaborator

    👋🏻 hey @awilnoaa , thanks for the excellent write-up! One of your colleagues reported something very similar a few months ago: #343

    We fixed that in #344, but looks like we didn't do a release with those changes yet. Could you install the package from source (clone this repo and R CMD INSTALL .) and let us know if that resolves the problem?

    @bburns632 could we do a new release to CRAN?

  2. awilnoaa commented on Aug 12, 2026

    @awilnoaa
    Author

    Thanks so much for the quick response and for pointing me to #343/#344. I didn't realize we had reached out about the same concern.

    I installed the GitHub/development version of pkgnet (0.6.0.9999) and reran the minimal FunctionReporter test on FIMS. The original externalptr / C++Function error is resolved! I also reran the HTML report without pkg_path, and the Function Network visualization renders.

    Thank you again for taking the time to help us with this!

  3. bburns632 commented on Aug 13, 2026

    @bburns632
    Collaborator

    @awilnoaa & @kellijohnson-NOAA, apologies for the delayed release. v0.6.1 of pkgnet with these issues resolved is queued in #349 and will be submitted once CRAN's submission window opens up again later this month.

  4. bburns632 commented on Sep 1, 2026

    @bburns632
    Collaborator

    v0.6.1 is released. Thank you for your patience, @awilnoaa & @kellijohnson-NOAA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions