-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
126 lines (85 loc) · 3.94 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
library("oeli")
```
# Utilities for developing R software <a href="https://loelschlaeger.de/oeli/"><img src="man/figures/logo.png" align="right" height="138" /></a>
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/oeli)](https://CRAN.R-project.org/package=oeli)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/last-month/oeli)](https://CRAN.R-project.org/package=oeli)
[![R-CMD-check](https://github.com/loelschlaeger/oeli/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/loelschlaeger/oeli/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/loelschlaeger/oeli/branch/master/graph/badge.svg)](https://app.codecov.io/gh/loelschlaeger/oeli?branch=master)
<!-- badges: end -->
The `{oeli}` package offers a collection of handy functions that I found useful while developing R packages. Perhaps you'll find them helpful too!
## Installation
The released package version can be installed from [CRAN](https://CRAN.R-project.org) via:
``` r
install.packages("oeli")
```
## Demos
The package includes helpers for various tasks and objects. Some demos are shown below. Click the headings for reference pages with documentation on all available helpers in each category.
### [Distributions](https://loelschlaeger.de/oeli/reference/index.html#distribution)
The package has density and sampling functions for distributions not in base R, such as Dirichlet, multivariate normal, truncated normal, and Wishart.
```{r, dirichlet}
ddirichlet(x = c(0.2, 0.3, 0.5), concentration = 1:3)
rdirichlet(concentration = 1:3)
```
For faster computation, [Rcpp](https://www.rcpp.org) implementations are also available:
```{r, mvnorm_fast}
microbenchmark::microbenchmark(
"R" = rmvnorm(mean = c(0, 0, 0), Sigma = diag(3)),
"Rcpp" = rmvnorm_cpp(mean = c(0, 0, 0), Sigma = diag(3))
)
```
### [Function helpers](https://loelschlaeger.de/oeli/reference/index.html#functional)
Retrieving default arguments of a `function`:
```{r, function_defaults}
f <- function(a, b = 1, c = "", ...) { }
function_defaults(f)
```
### [Indexing helpers](https://loelschlaeger.de/oeli/reference/index.html#indexing)
Create all possible permutations of vector elements:
```{r, permutations}
permutations(LETTERS[1:3])
```
### [Package helpers](https://loelschlaeger.de/oeli/reference/index.html#packaging)
Quickly have a basic logo for your new package:
```{r, package_logo, fig.align = 'center', fig.dim = c(7, 7), out.width = "50%"}
package_logo("my_package", brackets = TRUE, use_logo = FALSE)
```
How to print a `matrix` without filling up the entire console?
```{r, print_matrix}
x <- matrix(rnorm(10000), ncol = 100, nrow = 100)
print_matrix(x, rowdots = 4, coldots = 4, digits = 2, label = "what a big matrix")
```
And what about a `data.frame`?
```{r, print_data.frame}
x <- data.frame(x = rnorm(1000), y = LETTERS[1:10])
print_data.frame(x, rows = 7, digits = 0)
```
### [Simulation helpers](https://loelschlaeger.de/oeli/reference/index.html#simulation)
Let's simulate a Markov chain:
```{r, simulate_markov_chain}
Gamma <- sample_transition_probability_matrix(dim = 3)
simulate_markov_chain(Gamma = Gamma, T = 20)
```
### [Transformation helpers](https://loelschlaeger.de/oeli/reference/index.html#transformation)
The `group_data.frame()` function groups a given `data.frame` based on the values in a specified column:
```{r, group_data.frame}
df <- data.frame("label" = c("A", "B"), "number" = 1:10)
group_data.frame(df = df, by = "label")
```
### [Validation helpers](https://loelschlaeger.de/oeli/reference/index.html#validation)
Is my matrix a proper transition probability matrix?
```{r, check_transition_probability_matrix}
matrix <- diag(4)
matrix[1, 2] <- 1
check_transition_probability_matrix(matrix)
```