knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(callmethod)
A methods package with some simpler syntax at the cost of being a less transferable
You can install the released version of callmethod from Github with:
## install from Github remotes::install_github("mkearney/callmethod")
Define a method that's a wrapper around base::rnorm()
:
## define method r_norm <- function(n, m = 0, sd = 1) call_method("r_norm") ## set default r_norm.default <- function(...) rnorm(...) ## call method r_norm(10, 3)
Define a method that generates random ID strings:
## define method rstring <- function(n, collapse = "") call_method("random_string") ## define method default random_string.default <- function(...) { list(...)[[1]] } random_string.character <- function(...) { dots <- list(...) n <- nchar(dots[[1]]) collapse <- dots[[2]] random_string.numeric(n, collapse) } ## define method for numeric random_string.numeric <- function(...) { dots <- list(...) n <- dots[[1]] collapse <- dots[[2]] fl <- sample(letters, 2, replace = TRUE) paste(c(fl[1], sample(c(rep(0:9, 3), letters, toupper(letters)), n - 2, replace = TRUE), fl[2]), collapse = collapse) } ## call random_string method rstring(20) rstring("thislong")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.