https://github.com/hughjonesd/santoku
A versatile cutting tool for R
https://github.com/hughjonesd/santoku
Last synced: 8 days ago
JSON representation
A versatile cutting tool for R
- Host: GitHub
- URL: https://github.com/hughjonesd/santoku
- Owner: hughjonesd
- License: other
- Created: 2019-08-30T15:41:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-09-11T19:57:28.000Z (about 2 months ago)
- Last Synced: 2025-10-24T07:39:36.329Z (8 days ago)
- Language: JavaScript
- Homepage: https://hughjonesd.github.io/santoku
- Size: 20.3 MB
- Stars: 145
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - hughjonesd/santoku - A versatile cutting tool for R (JavaScript)
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# santoku 
[](https://CRAN.R-project.org/package=santoku)
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://CRAN.R-project.org/package=santoku)
[](https://hughjonesd.r-universe.dev/santoku)
[](https://github.com/hughjonesd/santoku/actions)
[](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).