https://github.com/mkearney/callmethod
🤙 Call Method for Developing Packages
https://github.com/mkearney/callmethod
devtools methods package-development r-methods r-package r-packages r-programming rstats
Last synced: about 1 month ago
JSON representation
🤙 Call Method for Developing Packages
- Host: GitHub
- URL: https://github.com/mkearney/callmethod
- Owner: mkearney
- License: other
- Created: 2018-09-16T15:12:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-16T15:17:30.000Z (over 6 years ago)
- Last Synced: 2024-11-15T03:12:34.897Z (3 months ago)
- Topics: devtools, methods, package-development, r-methods, r-package, r-packages, r-programming, rstats
- Language: R
- Homepage: https://github.com/mkearney/callmethod
- Size: 4.88 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - mkearney/callmethod - 🤙 Call Method for Developing Packages (R)
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(callmethod)
```
# callmethod> A methods package with some simpler syntax at the cost of being a less transferable
## Installation
You can install the released version of callmethod from Github with:
``` r
## install from Github
remotes::install_github("mkearney/callmethod")
```## Examples
Define a method that's a wrapper around `base::rnorm()`:
```{r 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:
```{r random_string}
## 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")
```