micturalgia
micturalgia

Reputation: 325

R error in get(search()[2]): object not found when trying to call a function from a loaded package

Having a very strange error when trying to use a package downloaded from Cran (epicalc). Some functions from this package work fine, but when I try to call one specific function (followup.plot), I get the following error:

Error in get(search()[2]) : object 'package:epicalc' not found Calls: followup.plot -> get

Any ideas what this means and how to fix it? Thanks!

Upvotes: 0

Views: 349

Answers (1)

mnel
mnel

Reputation: 115515

This appears to be a result of some rather "interesting" code within followup.plot

if (missing(xlab)) {
    xlab <- as.character(substitute(time))
    if (any(class(get(search()[2])) == "data.frame")) {
        if (any(attr(get(search()[2]), "names") == as.character(substitute(xlab)))) {
            if (!is.null(attr(get(search()[2]), "var.labels")[attr(get(search()[2]), 
              "names") == as.character(substitute(xlab))])) {
              if (attr(get(search()[2]), "var.labels")[attr(get(search()[2]), 
                "names") == as.character(substitute(xlab))] != 
                "") {
                xlab <- attr(get(search()[2]), "var.labels")[attr(get(search()[2]), 
                  "names") == as.character(substitute(xlab))]
              }
            }
        }
    }
}
if (missing(ylab)) {
    ylab <- as.character(substitute(outcome))
    if (any(class(get(search()[2])) == "data.frame")) {
        if (any(attr(get(search()[2]), "names") == as.character(substitute(ylab)))) {
            if (!is.null(attr(get(search()[2]), "var.labels")[attr(get(search()[2]), 
              "names") == as.character(substitute(ylab))])) {
              if (attr(get(search()[2]), "var.labels")[attr(get(search()[2]), 
                "names") == as.character(substitute(ylab))] != 
                "") {
                ylab <- attr(get(search()[2]), "var.labels")[attr(get(search()[2]), 
                  "names") == as.character(substitute(ylab))]
              }
            }
        }
    }
}

which assumes you have attached or used the source of your variables.

This is highly bizarre behaviour to assume (IMHO)

Upvotes: 1

Related Questions