Skip to content

Instantly share code, notes, and snippets.

@moodymudskipper
Created December 18, 2021 18:40
Show Gist options
  • Save moodymudskipper/f8e4753c1cb22a67df592a122b64de5f to your computer and use it in GitHub Desktop.
Save moodymudskipper/f8e4753c1cb22a67df592a122b64de5f to your computer and use it in GitHub Desktop.
subset to end
`[` <- function(x, ...) {
base::`[`(x, ...)
}
makeActiveBinding(".I", function() {
sc <- sys.calls()
fr <- which(vapply(sc, \(x) capture.output(x)[1], character(1)) == "base::`[`(x, ...)")
fr <- fr[length(fr)]
sf <- sys.frames()[[fr-1]]
x <- eval(quote(x), sf)
NROW(x)
}, .GlobalEnv)
makeActiveBinding(".J", function() {
sc <- sys.calls()
fr <- which(vapply(sc, \(x) capture.output(x)[1], character(1)) == "base::`[`(x, ...)")
fr <- fr[length(fr)]
sf <- sys.frames()[[fr-1]]
x <- eval(quote(x), sf)
NCOL(x)
}, .GlobalEnv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment