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

https://github.com/jansim/nicknames

Specify human readable names for the columns in your data once and then reuse them across your project to rename plots axes, dataframe columns, tables and anything else.
https://github.com/jansim/nicknames

data-cleaning data-visualization r r-package

Last synced: 10 months ago
JSON representation

Specify human readable names for the columns in your data once and then reuse them across your project to rename plots axes, dataframe columns, tables and anything else.

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%"
)
```

# nicknames

[![R-CMD-check](https://github.com/jansim/nicknames/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jansim/nicknames/actions/workflows/R-CMD-check.yaml)

Nicknames allows you to specify human readable names for the columns in your data once and then reuse them across your project to rename plots axes, dataframe columns, tables and anything else.

## Installation

You can install the development version of nicknames from [GitHub](https://github.com/) with:

``` r
# install.packages("pak")
pak::pak("jansim/nicknames")
```

## Example

With nicknames, you can register the mapping between columns in your data and human readable column names once and easily re-use them everywhere.

```{r ex-setup}
library(nicknames)

nn_register(c(
"mpg" = "Miles per Gallon",
"hp" = "Horsepower",
"cyl" = "Number of\nCylinders"
))
```

Including ggplot2 plots...

```{r ex-ggplot, fig.height=3, fig.width=7}
library(ggplot2)

# Create plot and apply nickname labels
ggplot(mtcars, aes(x = mpg, y = hp, color = factor(cyl))) +
geom_point() +
labs_nn()
```

...dataframes...

```{r ex-df, message=FALSE}
library(dplyr)

mtcars |>
select(mpg, hp, cyl) |>
nn() |>
head()
```

...and column names directly.

```{r ex-char}
nn("mpg")
```

While variables names are extracted from within function calls (e.g. `factor(cyl)` above), more exact matches take priority if you need to be precise.

```{r ex-ggplot-exact, fig.height=3, fig.width=7}
nn_register(c(
"factor(cyl)" = "Number of\nCylinders (factor)"
))

ggplot(mtcars, aes(x = mpg, y = hp, color = factor(cyl))) +
geom_point() +
labs_nn()
```