0

I am looking for the source code of a function (getRecursions from the package 'recurse') to see how it works. Here, are the steps I did:

getRecursions
function (x, radius, threshold = 0, timeunits = c("hours", 
    "secs", "mins", "days"), verbose = TRUE) 
{
    UseMethod("getRecursions", x)
}
<bytecode: 0x00000246a5983b30>
<environment: namespace:recurse>

methods(getRecursions)
[1] getRecursions.data.frame* getRecursions.Move*      
[3] getRecursions.MoveStack* 
see '?methods' for accessing help and source code

getAnywhere('getRecursions.data.frame')
A single object matching ‘getRecursions.data.frame’ was found
It was found in the following places
  registered S3 method for getRecursions from namespace recurse
  namespace:recurse
with value

function (x, radius, threshold = 0, timeunits = c("hours", 
    "secs", "mins", "days"), verbose = TRUE) 
{
    stopifnot(is.data.frame(x))
    stopifnot(ncol(x) == 4)
    stopifnot(radius > 0)
    timeunits = match.arg(timeunits)
    results = getRecursionsCpp(x[, 1], x[, 2], x[, 3], x[, 4], 
        x[, 1], x[, 2], radius, threshold, timeunits, verbose)
    results$timeunits = timeunits
    class(results) = "recurse"
    if (verbose) {
        class(results) = c("recurse", "recurse.verbose")
        dataTz = attr(x[, 3], "tzone")
        if (!is.null(dataTz)) {
            attr(results$revisitStats$entranceTime, "tzone") = dataTz
            attr(results$revisitStats$exitTime, "tzone") = dataTz
        }
    }
    return(results)
}
<bytecode: 0x00000247245c34c8>
<environment: namespace:recurse>

So, now I need to find the source code for the function 'getRecursionsCpp' as following:

getAnywhere('getRecursionsCpp')
A single object matching ‘getRecursionsCpp’ was found
It was found in the following places
  namespace:recurse
with value

function (trajX, trajY, trajT, trajId, locX, locY, radius, threshold, 
    timeunits, verbose) 
{
    .Call("_recurse_getRecursionsCpp", PACKAGE = "recurse", 
        trajX, trajY, trajT, trajId, locX, locY, radius, threshold, 
        timeunits, verbose)
}
<bytecode: 0x0000024745a6ea20>
<environment: namespace:recurse>

How can I find the source code for the function call .Call("_recurse_getRecursionsCpp")? I tried to use this recurse:::"_recurse_getRecursionsCpp", but it doesn't work.

Elodie
  • 1
  • 2
  • 4
    https://github.com/cran/recurse/blob/master/src/RecurseCalculator.cpp#L145 – rawr Dec 03 '21 at 17:39
  • Try `trace(what = recurse::getRecursions, edit = TRUE)`. Just be careful no to modify it right there, if that is not what you really want. – Nicolás Velasquez Dec 03 '21 at 17:39
  • 2
    `.Call(..)` means that it is accessing a function within a compiled shared object, usually stored in a file with an extension `.so`, `.lib`, or `.dll` (os-dependent). You cannot easily get source code from those objects, typically all you can do is reverse-engineer it, which is well outside the scope of R. The better way to find the source-code for non-R code (used by R) is to find the package repo (either original-author or on github.com/cran/..., as @rawr provided). – r2evans Dec 03 '21 at 17:41

0 Answers0