rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

Avoid `.Call()` in code other than `aaa-auto.R`

Open krlmlr opened this issue 2 years ago • 5 comments

All calls into C code should be autogenerated. This ensures that we either mess up big time (and notice it), or get it right.

In practice, this means hunting down all instances of .Call in user code and using autogenerated bindings instead. Related: #1044.

https://github.com/igraph/rigraph/pull/1057#issuecomment-1872612836

krlmlr avatar Dec 30 '23 21:12 krlmlr

One issue that will need to be solved (also for transitivity()) is what happened here: https://github.com/igraph/rigraph/pull/1028#issuecomment-1871607308 This problem went away for k_shortest_paths() after I figured out how to use the generated function directly (instead of calling it). But we'll need a solution when we call it. Do you have any suggestions @krlmlr ?

In short, suppose the function has a mode = c("out", "in", "all") parameter. Multiple values are allowed as a default, but not as a manually passed value. This poses an issue when passing the default mode to the _impl function.

szhorvat avatar Dec 30 '23 21:12 szhorvat

We can call rlang::arg_match() in the manual wrapper in such cases, before forwarding to _impl().

krlmlr avatar Dec 30 '23 22:12 krlmlr

Scratch that, we probably need igraph.match.arg() also in the manual wrapper.

krlmlr avatar Dec 30 '23 22:12 krlmlr

It's a case-insensitive version of match.arg(), and rlang::arg_match() is a version of that with better behavior and error messages.

krlmlr avatar Dec 30 '23 22:12 krlmlr

Now using the new switch_igraph_arg() for translating enums (=R strings) to integers.

krlmlr avatar Oct 26 '25 18:10 krlmlr