diff --git a/R/dotify.R b/R/dotify.R index 77f49bc..1759128 100644 --- a/R/dotify.R +++ b/R/dotify.R @@ -16,35 +16,13 @@ dotify <- function() { # make sure we have a handlers environment codetools <- asNamespace("codetools") - handlers <- codetools$collectUsageHandlers - if (!is.environment(handlers)) + collectUsageHandlers <- codetools$collectUsageHandlers + if (!is.environment(collectUsageHandlers)) return() - # make sure we have 'isUtilsVar' - if (!exists("isUtilsVar", envir = codetools)) - return() - - # check if 'isUtilsVar' has changed in an unexpected way - isUtilsVar <- codetools$isUtilsVar - expected <- pairlist(v = quote(expr = ), env = quote(expr = )) - if (!identical(formals(isUtilsVar), expected)) - return() - - # tell codetools to accept our code's handlers - # TODO: ask Luke nicely to allow us to do this - if (.BaseNamespaceEnv$bindingIsLocked("isUtilsVar", env = codetools)) { - .BaseNamespaceEnv$unlockBinding("isUtilsVar", env = codetools) - on.exit(.BaseNamespaceEnv$lockBinding("isUtilsVar", env = codetools), add = TRUE) - } - - # replace the binding - hack <- function(v, env) TRUE - environment(hack) <- codetools - assign("isUtilsVar", hack, envir = codetools) - # add our handler for subset-assignment - handler <- handlers$`[<-` %||% function(v, w) {} - handlers$`[<-` <- function(v, w) { + handler <- collectUsageHandlers$`[<-` %||% function(v, w) {} + collectUsageHandlers$`[<-` <- function(v, w) { # only handle dotty calls if (!identical(v[[2L]], dot)) { @@ -68,8 +46,4 @@ dotify <- function() { } - # included just for testing - .[a, b] <- c(1, 2) - c(a, b) - }