https://github.com/epiverse-trace/cleanepi
R package to clean and standardize epidemiological data
https://github.com/epiverse-trace/cleanepi
data-cleaning epidemiology epiverse r r-package
Last synced: 3 months ago
JSON representation
R package to clean and standardize epidemiological data
- Host: GitHub
- URL: https://github.com/epiverse-trace/cleanepi
- Owner: epiverse-trace
- License: other
- Created: 2023-02-27T12:46:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T14:37:55.000Z (12 months ago)
- Last Synced: 2024-10-25T08:57:39.102Z (12 months ago)
- Topics: data-cleaning, epidemiology, epiverse, r, r-package
- Language: R
- Homepage: https://epiverse-trace.github.io/cleanepi/
- Size: 9.43 MB
- Stars: 8
- Watchers: 3
- Forks: 3
- Open Issues: 28
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
README
---
output: github_document
always_allow_html: true
editor_options:
markdown:
wrap: 72
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = file.path("man", "figures", "README-"),
out.width = "100%"
)
```# {{ packagename }}: Clean and standardize epidemiological data
[](https://opensource.org/licenses/MIT)
[](https://github.com/epiverse-trace/cleanepi/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/epiverse-trace/cleanepi?branch=main)
[](https://www.reconverse.org/lifecycle.html#experimental)
[](https://zenodo.org/doi/10.5281/zenodo.11473984)**{{ packagename }}** is an R package designed for cleaning, curating, and standardizing epidemiological data. It streamlines various data cleaning tasks that are typically expected when working with datasets in epidemiology.
Key functionalities of **{{ packagename }}** include:
1. **Removing irregularities**: It removes duplicated and empty rows and columns, as well as columns with constant values.
2. **Handling missing values**: It replaces missing values with the standard `NA` format, ensuring consistency and ease of analysis.
3. **Ensuring data integrity**: It ensures the uniqueness of uniquely identified columns, thus maintaining data integrity and preventing duplicates.
4. **Date conversion**: It offers functionality to convert character columns to Date format under specific conditions, enhancing data uniformity and facilitating temporal analysis. It also offers conversion of numeric values written in letters into numbers.
5. **Standardizing entries**: It can standardize column entries into specified formats, promoting consistency across the dataset.
6. **Time span calculation**: It calculates the time span between two elements of type `Date`, providing valuable demographic insights for epidemiological analysis.
**{{ packagename }}** operates on data frames or similar structures like tibbles, as well as linelist objects commonly used in epidemiological research. It returns the processed data in the same format, ensuring seamless integration into existing workflows. Additionally, it generates a comprehensive report detailing the outcomes of each cleaning task.
**{{ packagename }}** is developed by the [Epiverse-TRACE](https://data.org/initiatives/epiverse/) team at the [Medical Research Council The Gambia unit at the London School of Hygiene and Tropical Medicine](https://www.lshtm.ac.uk/research/units/mrc-gambia).
## Installation
**{{ packagename }}** can be installed from CRAN using
```{r message=FALSE, eval=FALSE}
install.packages("cleanepi")
```The latest development version of **{{ packagename }}** can be installed from [GitHub](https://epiverse-trace.github.io/cleanepi/).
```{r message=FALSE}
if (!require("pak")) install.packages("pak")
pak::pak("{{ gh_repo }}")
library(cleanepi)
```## Quick start
The main function in **{{ packagename }}** is `clean_data(),` which internally makes call of almost all standard data cleaning functions, such as removal of empty and duplicated rows and columns, replacement of missing values, etc. However, each function can also be called independently to perform a specific task. This mechanism is explained in details in the **vignette**. Below is typical example of how to use the `clean_data()` function.
```{r eval=TRUE}
# READING IN THE TEST DATASET
test_data <- readRDS(
system.file("extdata", "test_df.RDS", package = "cleanepi")
)
``````{r echo=FALSE, eval=TRUE}
test_data %>%
kableExtra::kbl() %>%
kableExtra::kable_paper("striped", font_size = 14, full_width = TRUE) %>%
kableExtra::scroll_box(height = "200px", width = "100%",
box_css = "border: 1px solid #ddd; padding: 5px; ",
extra_css = NULL,
fixed_thead = TRUE)
``````{r eval=TRUE}
# READING IN THE DATA DICTIONARY
test_dictionary <- readRDS(
system.file("extdata", "test_dictionary.RDS", package = "cleanepi")
)
``````{r echo=FALSE, eval=TRUE}
test_dictionary %>%
kableExtra::kbl() %>%
kableExtra::kable_paper("striped", font_size = 14, full_width = TRUE)
``````{r eval=TRUE}
# DEFINING THE CLEANING PARAMETERS
replace_missing_values <- list(target_columns = NULL, na_strings = "-99")
remove_duplicates <- list(target_columns = NULL)
standardize_dates <- list(
target_columns = NULL,
error_tolerance = 0.4,
format = NULL,
timeframe = as.Date(c("1973-05-29", "2023-05-29")),
orders = list(
world_named_months = c("Ybd", "dby"),
world_digit_months = c("dmy", "Ymd"),
US_formats = c("Omdy", "YOmd")
)
)
standardize_subject_ids <- list(
target_columns = "study_id",
prefix = "PS",
suffix = "P2",
range = c(1, 100),
nchar = 7
)
remove_constants <- list(cutoff = 1)
standardize_column_names <- list(
keep = "date.of.admission",
rename = c(DOB = "dateOfBirth")
)
to_numeric <- list(target_columns = "sex", lang = "en")
``````{r eval=TRUE}
# PERFORMING THE DATA CLEANING
cleaned_data <- clean_data(
data = test_data,
standardize_column_names = standardize_column_names,
remove_constants = remove_constants,
replace_missing_values = replace_missing_values,
remove_duplicates = remove_duplicates,
standardize_dates = standardize_dates,
standardize_subject_ids = standardize_subject_ids,
to_numeric = to_numeric,
dictionary = test_dictionary,
check_date_sequence = NULL
)
``````{r echo=FALSE, eval=TRUE}
# VISUALISE THE CLEANED DATASET
cleaned_data %>%
kableExtra::kbl() %>%
kableExtra::kable_paper("striped", font_size = 14, full_width = FALSE) %>%
kableExtra::scroll_box(height = "200px", width = "100%",
box_css = "border: 1px solid #ddd; padding: 5px; ",
extra_css = NULL,
fixed_thead = TRUE)
``````{r eval=TRUE}
# EXTRACT THE DATA CLEANING REPORT
report <- attr(cleaned_data, "report")
``````{r eval=FALSE}
# DISPLAY THE DATA CLEANING REPORT
print_report(report)
```## Vignette
```{r eval=FALSE}
browseVignettes("cleanepi")
```### Lifecycle
This package is currently an *experimental*, as defined by the [RECON software
lifecycle](https://www.reconverse.org/lifecycle.html). This means that it is
functional, but interfaces and functionalities may change over time, testing and documentation may be lacking.### Contributions
Contributions are welcome via [pull
requests](https://github.com/{{ gh_repo }}/pulls).### Code of Conduct
Please note that the {{ packagename }} project is released with a [Contributor
Code of
Conduct](https://github.com/epiverse-trace/.github/blob/main/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.## Citing this package
```{r message=FALSE, warning=FALSE}
citation("cleanepi")
```