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.

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