Skip to content
Prev 366956 / 398506 Next

Function that works within a package and not when copied in global environment. Why?

Thanks Bert for the explanation about identical.

For the vectorize.args, note that vectorize.args is not a function but 
an variable that is unknown in the namespace nlWaldTest.

 > nlWaldTest::vectorize.args
Erreur : 'vectorize.args' n'est pas un objet export? depuis 
'namespace:nlWaldTest'


Furthermore, if the function is created from a copy of the original one:

smartsub <- getFromNamespace(".smartsub", ns="nlWaldTest")

or if it is created manually: by copy-paste of the code:

smartsub2 <- function (pat, repl, x)
  {
      args <- lapply(as.list(match.call())[-1L], eval, parent.frame())
      names <- if (is.null(names(args)))
          character(length(args))
      else names(args)
      dovec <- names %in% vectorize.args
      do.call("mapply", c(FUN = FUN, args[dovec], MoreArgs = 
list(args[!dovec]),
                          SIMPLIFY = SIMPLIFY, USE.NAMES = USE.NAMES))
  }

Both are defined in the global env, but the first one works and not the 
second one.

I am surprised and don't understand how it is possible.

Sincerely

Marc Girondot