Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sy <- base::summary
- nu <- function(x) length(unique(x))
- su <- function(x) sort(unique(x))
- oer <- function() options(error = utils::recover)
- oet <- function() options(error = traceback)
- oen <- function() options(error = NULL)
- colgrep <- function(pat) grep(pat, grDevices::colors(), value = TRUE)
- coldisplay <- function(cols) {
- cols <- colgrep(cols)
- x <- ceiling(sqrt(length(cols)))
- graphics::plot(rep(1:x, each = x)*2, rep(1:x, x), pch = 19, cex = 5, col = cols)
- graphics::text(rep(1:x, each = x)*2, rep(1:x, x), cols, pos = c(1,3),
- col = grDevices::adjustcolor(cols, .7, .7,.7,.7), pch = 0.7)
- }
- print.command <- function (cmd) {
- default.args <- attr(cmd, "default.args")
- if (length(default.args) == 0L) default.args <- list()
- res <- do.call(cmd, default.args, envir = parent.frame(2))
- if (attr(cmd, "print_result")) print(res)
- invisible(NULL)
- }
- make_command <- function(x, ..., print = TRUE) {
- class(x) <- c("command", class(x))
- attr(x, "default.args") <- list(...)
- attr(x, "print_result") <- print
- x
- }
- ls <- make_command(ls)
- oer <- make_command(oer, print = FALSE)
- oet <- make_command(oet, print = FALSE)
- oen <- make_command(oen, print = FALSE)
- lf <- make_command(list.files)
- getwd <- make_command(getwd)
- cat("My own functions:
- sy nu su ls lf getwd oer oet oen
- colgrep coldisplay make_command\n")
- cat("Commands which don't need brackets:
- ls lf getwd oer oet oen\n\n")
Add Comment
Please, Sign In to add comment