-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
210 lines (161 loc) · 7.58 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
---
output: github_document
always_allow_html: true
editor_options:
markdown:
wrap: 72
---
<!-- The code to render this README is stored in .github/workflows/render-readme.yaml -->
<!-- Variables marked with double curly braces will be transformed beforehand: -->
<!-- `packagename` is extracted from the DESCRIPTION file -->
<!-- `gh_repo` is extracted via a special environment variable in GitHub Actions -->
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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 <img src="man/figures/logo.svg" align="right" width="130"/>
<!-- badges: start -->
[](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)
<!-- badges: end -->
**{{ 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")
```