Guest User

Untitled

a guest
Mar 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. sy <- base::summary
  2. nu <- function(x) length(unique(x))
  3. su <- function(x) sort(unique(x))
  4. oer <- function() options(error = utils::recover)
  5. oet <- function() options(error = traceback)
  6. oen <- function() options(error = NULL)
  7. colgrep <- function(pat) grep(pat, grDevices::colors(), value = TRUE)
  8. coldisplay <- function(cols) {
  9. cols <- colgrep(cols)
  10. x <- ceiling(sqrt(length(cols)))
  11. graphics::plot(rep(1:x, each = x)*2, rep(1:x, x), pch = 19, cex = 5, col = cols)
  12. graphics::text(rep(1:x, each = x)*2, rep(1:x, x), cols, pos = c(1,3),
  13. col = grDevices::adjustcolor(cols, .7, .7,.7,.7), pch = 0.7)
  14. }
  15.  
  16.  
  17. print.command <- function (cmd) {
  18. default.args <- attr(cmd, "default.args")
  19. if (length(default.args) == 0L) default.args <- list()
  20. res <- do.call(cmd, default.args, envir = parent.frame(2))
  21. if (attr(cmd, "print_result")) print(res)
  22. invisible(NULL)
  23. }
  24.  
  25.  
  26. make_command <- function(x, ..., print = TRUE) {
  27. class(x) <- c("command", class(x))
  28. attr(x, "default.args") <- list(...)
  29. attr(x, "print_result") <- print
  30. x
  31. }
  32.  
  33.  
  34. ls <- make_command(ls)
  35. oer <- make_command(oer, print = FALSE)
  36. oet <- make_command(oet, print = FALSE)
  37. oen <- make_command(oen, print = FALSE)
  38. lf <- make_command(list.files)
  39. getwd <- make_command(getwd)
  40.  
  41. cat("My own functions:
  42. sy nu su ls lf getwd oer oet oen
  43. colgrep coldisplay make_command\n")
  44. cat("Commands which don't need brackets:
  45. ls lf getwd oer oet oen\n\n")
Add Comment
Please, Sign In to add comment