Skip to content

Commit

Permalink
hacking around isUtilsVar not necessary?
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Aug 20, 2024
1 parent ef65d00 commit 2cc063b
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions R/dotify.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -68,8 +46,4 @@ dotify <- function() {

}

# included just for testing
.[a, b] <- c(1, 2)
c(a, b)

}

0 comments on commit 2cc063b

Please sign in to comment.