You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The "conservative" approach to locating all globals while acknowledging library() calls, is to call those library() and require() statements before searching for globals. This will, as far as possible, imitate what is seen by the compute process.
Another approach would be to first search for globals and the drop those that are exported by the packages loaded by library() and require(). The latter can be queried using getNamespaceExports(), with the drawback that it will also load the package (but at least not attach it). UPDATE: It is not enough to look at getNamespaceExports() when there's a library() statement, because other packages may end up on the search() path.
> library(globals)
>expr<- substitute({ library(listenv); listenv })
## Some fancy way of inferring what package is attached## (This is where the real work has to be done)>gpkgs<-"listenv"## Attach all packages>dummy<- lapply(gpkgs, FUN=library, character.only=TRUE)
## Search for globals (gives error if unknown at this point)>g<- getGlobals(expr)
>g<- cleanup(g)
> str(g)
Listof1$listenv:function (length=0L)
- attr(*, "class")=chr [1:2] "Globals""list"## Drop the ones that are part of the packages attached>gpkgs<- lapply(g, FUN=function(obj) environmentName(environment(obj)))
>gpkgs<- unlist(gpkgs, use.names=TRUE)
>keep<-!is.element(gpkgs, pkgs)
>g<-g[keep]
> str(g)
Namedlist()
findGlobals()
does not acknowledge when expression attaches packages vialibrary()
etc, e.g.In case someone wonders about
library()
;The text was updated successfully, but these errors were encountered: