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

https://github.com/DoctorBJones/datadictionary

R data dictionary
https://github.com/DoctorBJones/datadictionary

Last synced: 5 months ago
JSON representation

R data dictionary

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


[![CRAN status](https://www.r-pkg.org/badges/version/datadictionary)](https://cran.r-project.org/package=datadictionary)
[![R-CMD-check](https://github.com/DoctorBJones/datadictionary/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/DoctorBJones/datadictionary/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/DoctorBJones/datadictionary/branch/main/graph/badge.svg)](https://app.codecov.io/gh/DoctorBJones/datadictionary?branch=main)

# datadictionary

The goal of `datadictionary` is to create a data dictionary from any dataframe or tibble in your R environment. While other packages exist I found they were complicated to use and/or the output wasn't what I was after. This package attempts to solve those problems by presenting tabular summaries of the dataset in a format that fits easily in a pane or screen, using a single line of code.

It includes an overall summary of the dataset and at-a-glance summaries of each variable. All variables have a count of missing included, and different summaries are provided based on the data class.

For factors, labelled data and logicals the summary will include the name of each level with the level number in parentheses where appropriate. A value for the count of units in each level is included.

For dates, integers and other numeric types of data the summary includes statistical summaries such as mean, median, mode, minimum and maximum. A value for each is included in the table.

Character variables include only a count of unique values and missing values. This is the default so if you include a class of data that isn't yet implemented you should get this output.

You can nominate one or more identifier variables, for example individuals and clusters, so you only get a count of unique and missing values rather than nonsense numeric summaries.

You can also include a vector to add labels if you want descriptions included in the document. Lastly, you can opt for the output to write directly to Excel.

## Installation

You can install the current version of `datadictionary` from CRAN using:

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

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

``` r
# install.packages("devtools")
devtools::install_github("DoctorBJones/datadictionary")
```

## Example

You can print a basic data dictionary directly to your console or assign it to an object in your environment:

```{r}
library(datadictionary)

create_dictionary(esoph)

esoph_dictionary <- create_dictionary(esoph)
```

You specify one or more identifier variables by passing a quoted string or vector of quoted strings to `id_var`. This is useful if you have hierarchical data, for example and have identifiers for individuals, clusters or blocks.

```{r}

# create fake id variables
mtcars$id1 <- 1:nrow(mtcars)
mtcars$id2 <- mtcars$id1*10

create_dictionary(mtcars, id_var = c("id1", "id2"))

```
You can also optionally add labels for unlabelled variables. You need to pass a named vector to `var_labels` where the names
correspond to columns in your dataset. The vector must be of the same length as your dataset.

```{r}

# Create labels as a named vector.
iris.labels <- c(Sepal.Length = "Sepal length in mm",
Sepal.Width = "Sepal width in mm",
Petal.Length = "Petal length in mm",
Petal.Width = "Petal width in mm",
Species = "Species of iris")

create_dictionary(iris, var_labels = iris.labels)
```

You can also write directly to Excel from the `create_dictionary` function if you pass a file path and name as a quoted string to the `file` parameter. There is no visible output for this use.

```{r, eval = FALSE}

create_dictionary(ChickWeight, file = "chickweight_dictionary.xlsx")

```

The package also includes a function to create a summary of a single variable in your dataset. There are no other arguments to this function.
```{r}

summarise_variable(iris, "Sepal.Length")

summarise_variable(ChickWeight, "Diet")
```