Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hughjonesd/santoku

A versatile cutting tool for R
https://github.com/hughjonesd/santoku

Last synced: 14 days ago
JSON representation

A versatile cutting tool for R

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)

```

# santoku santoku logo

[![CRAN status](https://www.r-pkg.org/badges/version/santoku)](https://CRAN.R-project.org/package=santoku)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN Downloads Per Month](http://cranlogs.r-pkg.org/badges/santoku)](https://CRAN.R-project.org/package=santoku)
[![R-universe](https://hughjonesd.r-universe.dev/badges/santoku)](https://hughjonesd.r-universe.dev/santoku)
[![R-CMD-check](https://github.com/hughjonesd/santoku/workflows/R-CMD-check/badge.svg)](https://github.com/hughjonesd/santoku/actions)
[![Codecov test coverage](https://codecov.io/gh/hughjonesd/santoku/branch/master/graph/badge.svg)](https://app.codecov.io/gh/hughjonesd/santoku?branch=master)

santoku is a versatile cutting tool for R. It provides `chop()`, a replacement
for `base::cut()`.

## Installation

Install from [r-universe](https://r-universe.dev):

``` r
install.packages("santoku", repos = c("https://hughjonesd.r-universe.dev",
"https://cloud.r-project.org"))
```

Or from CRAN:

``` r
install.packages("santoku")
```

Or get the development version from github:

``` r
# install.packages("remotes")
remotes::install_github("hughjonesd/santoku")
```

```{r, child = 'advantages.Rmd'}
```

## Examples

```{r}
library(santoku)
```

`chop` returns a factor:

```{r}
chop(1:5, c(2, 4))
```

Include a number twice to match it exactly:

```{r}
chop(1:5, c(2, 2, 4))
```

Use names in breaks for labels:

```{r}
chop(1:5, c(Low = 1, Mid = 2, High = 4))
```

Or use `lbl_*` functions:

```{r}
chop(1:5, c(2, 4), labels = lbl_dash())
```

Chop into fixed-width intervals:

```{r}
chop_width(runif(10), 0.1)
```

Or into fixed-size groups:

```{r}
chop_n(1:10, 5)
```

Chop dates by calendar month, then tabulate:

```{r}
library(lubridate)

dates <- as.Date("2021-12-31") + 1:90

tab_width(dates, months(1), labels = lbl_discrete(fmt = "%d %b"))
```

For more information, see the [vignette](https://hughjonesd.github.io/santoku/articles/santoku.html).