A reusable toolkit of personal R utility functions to support data processing, spatial workflows, modelling, and general analysis across projects.
You can install the package directly from GitHub:
devtools::install_github("bgcasey/utilR")The package includes the following utility functions:
add_alberta_flag()- Add Alberta flag to a site data frame using provincial boundariesextract_by_year()- Extract raster values by year from spatial featuresparallel_extract_directory()- Parallel extraction of raster data stored in a directory
estimate_processing_time()- Estimate total processing time based on subsetformat_time_diff()- Format time difference as days, hours, minutes, and seconds
load_most_recent_data()- Load the most recent .RData file dynamicallyload_rdata_files()- Load .RData files into a listread_tifs_to_list()- Read TIF files into a named listread_tifs_to_multiband()- Read TIF files into a multiband raster object
select_one_response()- Select a single response column from dataselect_species()- Select a specific species columnsample_blocks()- Sample a fraction of rows within blockssnake_case()- Convert strings to snake_casesummarize_column_classes()- Generate a data frame of column classes
set_terra_options()- Set Terra options with buffer for memory management
theme_science()- Minimal theme for scientific plotstheme_science_map()- Minimal theme for scientific map plotsstyle_active_file()- Style the active R file using styler
library(utilR)
# Example: Convert strings to snake_case
snake_case(c("Normal 1991_2020 AHM", "Normal 1991_2020 bFFP"))
# Example: Format time difference
start_time <- Sys.time()
Sys.sleep(5)
end_time <- Sys.time()
format_time_diff(start_time, end_time)
# Example: Use custom ggplot2 theme
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
labs(title = "Example Plot", x = "Weight", y = "MPG") +
theme_science()The package requires the following R packages:
- dplyr
- sf
- terra
- rnaturalearth
- ggplot2
- glue
- parallel
MIT