From Idea to CRAN: My Journey Building the `splitr` R Package
Source: Dev.to
Step 1: The Idea and the Blueprint
If you’ve ever thought, “I wish R could do X automatically,” I have a story for you. I embarked on a journey to create my first R package—splitr—which splits an Excel sheet into multiple sheets efficiently, using data.table for speed and openxlsx for Excel handling.
The goal
- Read a source Excel sheet
- Split rows into
nchunks - Write each chunk into a separate sheet in a single workbook
- Apply styles and optionally save to disk
Step 2: Structuring the Package
Using RStudio, I created a new package project called splitr. The basic structure looks like this:
splitr/
├── R/
│ └── split_excel_to_sheets.R
├── man/
├── DESCRIPTION
├── NAMESPACE
└── splitr.Rproj
DESCRIPTIONholds metadata about the package.R/is where the actual function lives.man/will eventually contain documentation generated with roxygen2.
Step 3: Writing the Function
Here’s the core of splitr:
split_excel_to_sheets
Note: CRAN submission is still in progress, so GitHub is the best way to try it right now.