My Favorite R Packages for Simple to Complex, Research to Administrative Data
How a set of packages combine into one pipeline for cleaning, analyzing, and visualizing complex datasets — and why that combination helps your mental health during complex data manipulations.
In the past 10 years of my R journey, I have used several packages and libraries, but a consistent set has appeared in almost every data cleaning and visualization project I have worked on. Here is each package, the functions I reach for most, and how they fit together.
library(readxl)
library(tidyverse)
library(dlookr)
library(eeptools)
library(lubridate)
library(ggplot2)
library(janitor)
library(table1)
library(writexl)
1. readxl: Getting Excel Data In
readxl reads .xls and .xlsx files without needing Java or Excel installed. Real-world workbooks often have multiple sheets and messy layouts, and readxl gives you the control to deal with them.
Key functions
read_excel()— withsheet,range,skip,col_types, andnaargumentsexcel_sheets()— list the tabs in a workbookcell_cols()/cell_rows()— specify precise ranges
A pattern I use constantly is reading every sheet of a workbook at once:
data <- read_excel(path, sheet = "sheet")
2. tidyverse: The Backbone
The tidyverse — my favorite — is a collection of packages (dplyr, tidyr, readr, purrr, stringr, forcats, tibble, and more) that share one design philosophy: tidy data and readable, pipeable code. It is the engine of almost every step below.
Key functions
mutate(),filter(),select(),arrange()— the everyday verbs ofdplyrgroup_by()+summarise()— split-apply-combine in two linesacross()— apply one transformation to many columns at onceleft_join(),inner_join(),anti_join()— combining tablespivot_longer()/pivot_wider()— reshaping between wide and long formatscase_when(),if_else()— recoding logicstr_detect(),str_replace()(stringr) andfct_lump(),fct_reorder()(forcats)
df %>%
filter(!is.na(income)) %>%
mutate(income_group = case_when(
income < 25000 ~ "Low",
income < 75000 ~ "Middle",
TRUE ~ "High"
)) %>%
group_by(income_group) %>%
summarize(Count = n()) %>%
ungroup()
3. ggplot2: The Visualization Grammar
ggplot2 is built on the Grammar of Graphics: you map variables to aesthetics, add geometric layers, and refine with scales, facets, and themes. It is technically part of the tidyverse, so loading it separately is harmless but redundant.
Key functions
ggplot()withaes()— set up data and mappingsgeom_point(),geom_line(),geom_col(),geom_histogram(),geom_boxplot(),geom_smooth()facet_wrap()/facet_grid()— small multiples, which are invaluable for complex datascale_*()andlabs()— colors, axes, titlestheme_minimal(),theme()— polishggsave()— export publication-ready figures
ggplot(df, aes(x = year, y = rate)) +
geom_bar(stat = "identity") +
labs(title = "Rate by Year", y = "Rate per 1,000") +
theme_minimal()
4. lubridate: Taming Dates and Times
Sometimes dates can be extremely messy and formatted differently within the same dataset. There are many libraries to wrangle dates, but lubridate is my favorite for date manipulation. It parses almost any format with intuitive function names and makes date arithmetic painless. (It is loaded automatically with tidyverse 2.0 and later.)
Key functions
ymd(),mdy(),dmy(),ymd_hms()— parse dates regardless of separatorsyear(),month(),wday(),quarter()— extract componentsfloor_date(),round_date()— bucket dates into weeks, months, or yearsinterval(),%within%,duration(),period()— time spans and durationstoday(),now()
df <- df %>%
mutate(
visit_date = mdy(visit_date),
visit_month = floor_date(visit_date, "month"),
days_since_enroll = as.numeric(visit_date - enroll_date)
)
5. dlookr: Data Diagnosis and Exploration
I call this one the time saver. With one function, you get a clear view of data quality. Even though newer user interfaces and tools like Positron include some of these features by default, dlookr remains especially useful in environments where AI integration is not permitted.
dlookr (Data Diagnosis, Exploration, and Transformation) is built for the first look at a dataset and the quality checks that follow. It reports variable types, missing values, and outliers; imputes and transforms; and can generate complete reports automatically.
Key functions
diagnose(),diagnose_numeric(),diagnose_category()— types, missing counts, unique values, and zero or negative counts for every variablefind_na(),find_outliers(),diagnose_outlier(),plot_outlier()— locate and visualize problem valuesimputate_na(),imputate_outlier()— fill missing values (mean, median, mode, knn, rpart, mice) and cap outliers, with aplot()method to compare before and afterdescribe(),normality(),plot_normality()— summary statistics, skewness, and normality checkscorrelate(),plot_correlate()— correlation matrices and plotstarget_by()+relate()— how an outcome relates to each predictortransform(),binning(),find_skewness()— rescale, log-transform, or bin variablesdiagnose_report(),eda_report(),transformation_report()— full HTML reports (PDF output requires LaTeX)
A word of caution:
dlookrpulls in many dependencies and includes its owntransform()function, so read your startup messages for masked functions. The report functions can also be slow on very large datasets, so try them on a sample first.
6. eeptools: Handy Utilities for Education and Applied Research
eeptools was created for education researchers, but it contains small utilities that save time in any applied project. I came across it through a colleague and immediately appreciated the age_calc function in particular.
Key functions
age_calc()— accurate age in years, months, or days from a birth date and a reference date, with correct handling of leap yearsisid()— checks whether a variable (or combination) uniquely identifies rows, which is a great sanity check before joinsdecomma()— converts strings like"1,234"to numbersstatamode()— a mode function with sensible tie behavior
df <- df %>%
mutate(age_at_visit = age_calc(dob, enddate = visit_date, units = "years"))
Pair age_calc() with lubridate-parsed dates and you get dependable age variables — the foundation of nearly every demographic analysis.
7. janitor: Cleaning with Minimal Fuss
janitor handles the unglamorous but essential chores: standardizing column names, finding duplicates, and building quick, clean frequency tables. I particularly enjoy adorn() and its companion functions.
Key functions
clean_names()— converts messy headers like"Patient ID #"intopatient_idremove_empty()— drops all-empty rows and columns (a common Excel artifact)get_dupes()— shows duplicated records so you can investigate themtabyl()withadorn_totals(),adorn_percentages(),adorn_pct_formatting()— tidy cross-tabsrow_to_names()— promote a data row to the headerexcel_numeric_to_date()— fix Excel serial dates that import as44197compare_df_cols()— diagnose whybind_rows()fails across files
df %>%
clean_names() %>%
remove_empty(c("rows", "cols")) %>%
tabyl(sex, race) %>%
adorn_percentages("row") %>%
adorn_pct_formatting(digits = 1)
8. table1: The Publication-Ready "Table 1"
Most research papers and reports open with a descriptive table comparing groups. table1 builds it in one line with a formula interface, automatically choosing appropriate summaries for continuous and categorical variables. I came across it during the COVID-19 pandemic and immediately adopted it as an essential package.
Key functions
table1()— the main function, using~ var1 + var2 | grouplabel()andunits()— attach readable names and units to variablesrender.continuousandrender.categorical— customize which statistics appear (for example, median and IQR)t1flex()— convert the table for Word or PowerPoint viaflextable
label(df$age) <- "Age"
units(df$age) <- "years"
table1(~ age + sex + race + income_group | treatment, data = df)
Because it reads the labels you set earlier, the cleaner your upstream work, the nicer the final table looks.
9. writexl: Getting Excel Data Out
Stakeholders often want results in Excel. writexl is a lightweight, dependency-free way to write .xlsx files.
Key function
write_xlsx()— pass a single data frame, or a named list of data frames to create one sheet per element
write_xlsx(data, path = "results.xlsx")
Combine it with map() and the output side of your pipeline becomes as automated as the input side.
How They All Come Together
The real value is how these packages hand off to one another. A typical large, complex project flows through five stages.
Stage 1: Acquire
Use readxl to ingest multi-sheet workbooks from collaborators. At this stage the data is faithful to its source — and often messy.
Stage 2: Standardize and Clean
janitor normalizes column names, removes empty rows, and flags duplicates. lubridate converts every date to a true Date type. eeptools validates keys with isid() and computes ages. The tidyverse (dplyr, tidyr, stringr, forcats) does the heavy lifting: recoding with case_when(), joining files, reshaping, and handling missing values.
Stage 3: Describe and Diagnose
table1 produces the summary table by group, and janitor::tabyl() gives quick cross-tabs. dlookr adds a systematic health check: diagnose() and diagnose_outlier() report missingness and outliers across every variable at once, and imputate_na() handles the gaps you decide to fill.
Stage 4: Explore and Visualize
dlookr checks distributions, outliers, and correlations, and ggplot2 visualizes both the raw data and the patterns you find. Because dlookr works on data frames and plays well with the pipe, its output feeds straight back into dplyr.
Stage 5: Deliver
writexl exports the cleaned data, the summary tables, and the flagged duplicates as sheets in a single workbook for stakeholders, while ggsave() writes the figures.
Why This Combination Works
- Shared conventions. Almost all of these packages work on data frames and tibbles, return data frames, and play well with the pipe, so output from one step is ready input for the next.
- Division of labor. Each package does one job well: reading, cleaning, dates, tables, diagnostics, plots, exporting. You rarely need to write custom code for chores that have a tested function.
- Reproducibility. The entire path from raw file to final workbook lives in one script. When the source data is updated, you rerun the script instead of redoing hours of manual work.
- Scale. The same code that cleans 500 rows cleans 5 million. Where files get very large, you can lean on
readr's fast readers and tools like IPUMS to select only the variables and samples you need.
References
Wickham, H., Bryan, J., Posit, et al. (n.d.). readxl: Read Excel Files (v. 1.6.0). CRAN. https://cran.r-project.org/web/packages/readxl/refman/readxl.html
Wickham, H., & RStudio. (2023, February 22). tidyverse: Easily Install and Load the "Tidyverse" (v. 2.0.0). CRAN. https://cran.r-project.org/web/packages/tidyverse/index.html
Ryu, C. (2025, August 31). dlookr: Tools for Data Diagnosis, Exploration, Transformation (v. 0.6.5). CRAN. https://cran.r-project.org/web/packages/dlookr/index.html
Becker, J. P., & Knowles, J. E. (2026, June 22). eeptools: Convenience Functions for Education Data (v. 1.3.0). CRAN. https://cran.r-project.org/web/packages/eeptools/index.html
Spinu, V., Grolemund, G., Wickham, H., et al. (2026, February 4). lubridate: Make Dealing with Dates a Little Easier (v. 1.9.5). CRAN. https://cran.r-project.org/web/packages/lubridate/index.html
Wickham, H., Chang, W., Henry, L., et al. (2026, April 22). ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics (v. 4.0.3). CRAN. https://cran.r-project.org/web/packages/ggplot2/index.html
Firke, S., Denney, B., Haid, C., Knight, R., Grosser, M., & Zadra, J. (2024, December 22). janitor: Simple Tools for Examining and Cleaning Dirty Data (v. 2.2.1). CRAN. https://cran.r-project.org/web/packages/janitor/index.html
Rich, B. (2025, September 19). table1: Tables of Descriptive Statistics in HTML (v. 1.5.1). CRAN. https://cran.r-project.org/web/packages/table1/index.html
Ooms, J., Denney, B., & McNamara, J. (2026, August 21). writexl: Export Data Frames to Excel "xlsx" Format (v. 2.0.1). CRAN. https://cran.r-project.org/web/packages/writexl/index.html
AI Claude Sonnet 5.5 was used for language refinement.
Explore Topics
Written by
Dr. Komi Modji, MD, MPH
Physician-epidemiologist and founder of Excellence Data Consulting. Since 2018, I have helped health departments, nonprofits, community organizations and researchers turn their data into decisions that improve health. English | Français.
Learn more →