0

I am trying to use the stepacross function in the vegan package of R.

When I do, it throws an error and fails to run the code

Error in stepacross(distance.dat, path = "extended") : object 'C_stepacross' not found

Anybody know the cause of this or what to do to fix it?

I'm using R (64-bit) 4.0.2 and vegan 2.5-6 (old version use is intentional).

It worked a few weeks ago, and I have made no changes since.

The C_stepacross object in question shows up in the stepacross() function code:

getAnywhere(stepacross)

function (dis, path = "shortest", toolong = 1, trace = TRUE, 
    ...) 
{
    path <- match.arg(path, c("shortest", "extended"))
    if (!inherits(dis, "dist")) 
        dis <- as.dist(dis)
    oldatt <- attributes(dis)
    n <- attr(dis, "Size")
    if (path == "shortest") 
        dis <- .C(dykstrapath, dist = as.double(dis), n = as.integer(n), 
            as.double(toolong), as.integer(trace), out = double(length(dis)), 
            NAOK = TRUE)$out
    else dis <- .C(C_stepacross, dis = as.double(dis), as.integer(n), 
        as.double(toolong), as.integer(trace), NAOK = TRUE)$dis
    attributes(dis) <- oldatt
    attr(dis, "method") <- paste(attr(dis, "method"), 
        path)
    dis
}
theforestecologist
  • 4,667
  • 5
  • 54
  • 91
  • The interface to the C function was last changed in vegan 2.5-1 (Apr 2018) when compiled routines had to be registred in R. It seems that you manage to avoid that registration. Have you loaded vegan in regular way? Do you have stray stepacross R function which is not in the vegan NAMESPACE but in your private workspace? As given, your problem is non-reproducible. – Jari Oksanen Feb 01 '23 at 09:32
  • If you intentionally use obsolete vegan from 2019, you have bad intentions. – Jari Oksanen Feb 01 '23 at 09:34
  • I'm simply relying on a computer that is too old and lacking internet connection to run some repeat analyses from 6 years ago. It's an annoying situation, but I'm dealing with it as best as I can. It's not a bad intention, just a frustrating one. – theforestecologist Feb 02 '23 at 19:35
  • to answer your question, I use `library(vegan)` and then run `stepacross()` – theforestecologist Feb 02 '23 at 19:41

1 Answers1

1

You don't provide a reproducible example, but I can reproduce this problem if I don't use vegan::stepacross, but a different copy of the function. Check your workspace – it probably has a copy of this function. The C function is registred for use in vegan functions, but not for functions in other namespaces. This example will reproduce your problem:

library(vegan)
data(dune)
d <- vegdist(dune)
stepacross <- vegan::stepacross
environment(stepacross) <- environment() ## set to working environment
dd <- stepacross(d, "ext") 
## Error in stepacross(d, "ext") : object 'C_stepacross' not found
dd <- vegan::stepacross(d, "ext") ### this will be OK
rm(stepacross) ## removes the local copy
dd <- stepacross(d, "ext") ## this will be OK: vegan copy was untouched

If getAnyewhere finds first a vegan version of stepacross, the last line of its output will be

<environment: namespace:vegan>

In your example this line was missing suggesting that your copy of stepacross was not in namespace:vegan. Moreover, getAnywhere should give package:vegan as the first place where this function was found.

Jari Oksanen
  • 3,287
  • 1
  • 11
  • 15
  • I tried to produce a reproducible example, but I could not -- I didn't fully understand what was causing the problem. I'm also unclear why this is occurring on my computer as you describe since It's worked fine on this particular computer for weeks leading up to having this issue. Now that you've given me a bit more knowledge of how some of this works on the backend, I'll take a look again at my problem and see if I can determine the ultimate source of the issue. Thanks! – theforestecologist Feb 02 '23 at 19:38