.Call
seems rather poorly documented; ?.Call
gives an explanation of the PACKAGE
argument:
PACKAGE
: if supplied, confine the search for a character string.NAME
to the DLL given by this argument (plus the conventional extension, ‘.so’, ‘.dll’, ...).This argument follows
...
and so its name cannot be abbreviated.This is intended to add safety for packages, which can ensure by using this argument that no other package can override their external symbols, and also speeds up the search (see ‘Note’).
And in the Note:
If one of these functions is to be used frequently, do specify
PACKAGE
(to confine the search to a single DLL) or pass.NAME
as one of the native symbol objects. Searching for symbols can take a long time, especially when many namespaces are loaded.You may see
PACKAGE = "base"
for symbols linked into R. Do not use this in your own code: such symbols are not part of the API and may be changed without warning.
PACKAGE = ""
used to be accepted (but was undocumented): it is now an error.
But there are no usage examples.
It's unclear how the PACKAGE
argument works. For example, in answering this question, I thought the following should have worked, but it doesn't:
.Call(C_BinCount, x, breaks, TRUE, TRUE, PACKAGE = "graphics")
Instead this works:
.Call(graphics:::C_BinCount, x, breaks, TRUE, TRUE)
Is this simply because C_BinCount
is unexported? I.e., if the internal code of hist.default
had added PACKAGE = "graphics"
, this would have worked?
This seems simple but is really rare to find usage of this argument; none of the sources I found give more than passing mention (1, 2, 3, 4, 5)... Examples of this actually working would be appreciated (even if it's just citing code found in an existing package)
(for self-containment purposes, if you don't want to copy-paste code from the other question, here are x
and breaks
):
x = runif(100000000, 2.5, 2.6)
nB <- 99
delt <- 3/nB
fuzz <- 1e-7 * c(-delt, rep.int(delt, nB))
breaks <- seq(0, 3, by = delt) + fuzz