File: tidyselect.R

package info (click to toggle)
r-cran-tidyselect 1.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 556 kB
  • sloc: sh: 13; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 932 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#' @import rlang
#' @importFrom glue glue
#' @importFrom purrr discard map map_chr map_if map_lgl map2 map2_chr
#'   detect_index negate walk every compact
#' @keywords internal
"_PACKAGE"


maybe_hotpatch_dplyr <- function(...) {
  if (!isNamespaceLoaded("dplyr")) {
    return(FALSE)
  }
  if (utils::packageVersion("dplyr") > "0.7.4") {
    return(FALSE)
  }

  fns <- list(
    current_vars = peek_vars,
    set_current_vars = poke_vars
  )
  env <- ns_env("dplyr")
  nms <- names(fns)

  for (i in seq_along(fns)) {
    hotpatch_binding(nms[[i]], fns[[i]], env)
  }

  TRUE
}
hotpatch_binding <- function(binding, fn, env) {
  unlock <- env_get(base_env(), "unlockBinding")
  unlock(binding, env)

  env_bind(env, !! binding := fn)

  lock <- env_get(base_env(), "lockBinding")
  lock(binding, env = env)
}

.onLoad <- function(...) {
  maybe_hotpatch_dplyr()
  setHook(packageEvent("dplyr", "onLoad"), maybe_hotpatch_dplyr)
}