diff --git a/DESCRIPTION b/DESCRIPTION index d768703..b64a33b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: codetools -Version: 0.2-15 +Version: 0.2-16 Priority: recommended Author: Luke Tierney Description: Code analysis tools for R. @@ -8,6 +8,6 @@ Depends: R (>= 2.1) Maintainer: Luke Tierney License: GPL NeedsCompilation: no -Packaged: 2016-10-05 12:32:32 UTC; luke +Packaged: 2018-12-22 14:48:17 UTC; luke Repository: CRAN -Date/Publication: 2016-10-05 16:36:47 +Date/Publication: 2018-12-24 12:40:05 UTC diff --git a/MD5 b/MD5 index 848cd07..51faa5d 100644 --- a/MD5 +++ b/MD5 @@ -1,8 +1,8 @@ -dfa8498b455155a5b2fc59c318c55f3f *DESCRIPTION +e48906bf15c7ce12219499d2ef9a442a *DESCRIPTION d7d4587719d6cbb3083123501ec23dd3 *NAMESPACE -e1a0def8009a2bc24365d7c1d0e9111d *R/codetools.R +898067d87a5ce3373b6a5b83c150746c *R/codetools.R 2af77179b93b37abb2717ba0dacd60a3 *man/checkUsage.Rd -215ca204e6c7206111e585206cee095c *man/codetools.Rd -31aabac379a9264e4ce819755b95b601 *man/findGlobals.Rd +722f473fac8f4c14d9fc199953daab44 *man/codetools.Rd +29fbed23cf38b444df2df0ce0389946b *man/findGlobals.Rd 7915e973bb95db1197db9152d339f2c8 *man/showTree.Rd 838118aa4116e6b2d66e393dae8e4073 *tests/tests.R diff --git a/R/codetools.R b/R/codetools.R index 3a8715a..b492597 100644 --- a/R/codetools.R +++ b/R/codetools.R @@ -376,8 +376,10 @@ makeUsageCollector <- function(fun, ..., name = NULL, finishCollectLocals = doNothing, warn = warning0, signal = signalUsageIssue) { - if (typeof(fun) != "closure") - stop("only works for closures") + if (typeof(fun) == "closure") + env <- environment(fun) + else + env <- .GlobalEnv makeCodeWalker(..., name = name, enterLocal = enterLocal, enterGlobal = enterGlobal, @@ -389,8 +391,8 @@ makeUsageCollector <- function(fun, ..., name = NULL, leaf = collectUsageLeaf, call = collectUsageCall, handler = getCollectUsageHandler, - globalenv = environment(fun), - env = environment(fun), + globalenv = env, + env = env, name = NULL, srcfile = NULL, frow = NULL, @@ -764,7 +766,7 @@ addCollectUsageHandler("if", "base", function(e, w) { }) ## -## Finding globa variables +## Finding global variables ## findGlobals <- function(fun, merge = TRUE) { diff --git a/man/codetools.Rd b/man/codetools.Rd index 5dd5b91..d2057ed 100644 --- a/man/codetools.Rd +++ b/man/codetools.Rd @@ -61,7 +61,7 @@ walkCode(e, w = makeCodeWalker()) } \description{ These functions provide some tools for analysing R code. Mainly - indented to support the other tools in this package and byte code + intended to support the other tools in this package and byte code compilation. } \author{Luke Tierney} diff --git a/man/findGlobals.Rd b/man/findGlobals.Rd index 111d08b..2aeea2b 100644 --- a/man/findGlobals.Rd +++ b/man/findGlobals.Rd @@ -5,12 +5,13 @@ findGlobals(fun, merge = TRUE) } \alias{findGlobals} \arguments{ - \item{fun}{closure.} + \item{fun}{function object; usually a closure.} \item{merge}{logical} } \value{ Character vector if \code{merge} is true; otherwise, a list with - \code{functions} and \code{variables} components. + \code{functions} and \code{variables} character vector components. + Character vectors are of length zero For non-closures. } \description{ Finds global functions and variables used by a closure.