csutil

Overview

csutil holds functions that help with common base-R problems.

Base-R lists are flexible, and that flexibility makes them awkward to check. csutil supplies seven functions. Four answer a yes/no question about the shape of a list. Three transform a vector or a list. The package defines no S3 classes and keeps no state between calls.

Installation

install.packages("csutil")

# development version
remotes::install_github("niphr/csutil")

Quick start

library(csutil)

# compute on the unique values only, then map the answers back
x <- c("oslo", "bergen", "oslo", "tromso", "oslo")
apply_fn_via_hash_table(x, toupper)
#> [1] "OSLO"   "BERGEN" "OSLO"   "TROMSO" "OSLO"

# chop a vector into runs of three
easy_split(1:7, size_of_each_group = 3)
#> $`1`
#> [1] 1 2 3
#>
#> $`2`
#> [1] 4 5 6
#>
#> $`3`
#> [1] 7

Which function do I want?

Question or task Function
Is every element of this list named? is_fully_named_list()
Is every element either NULL or a data frame? is_all_list_elements_null_or_df()
Is every element either NULL or a list? is_all_list_elements_null_or_list()
Is every element either NULL or a fully named list? is_all_list_elements_null_or_fully_named_list()
Chop a vector into groups of a fixed size, or into a requested number of groups easy_split()
Gather repeated results into one data.table per name unnest_dfs_within_list_of_fully_named_lists()
Skip repeated work when a long vector holds few unique values apply_fn_via_hash_table()

Each of the four predicates returns TRUE or FALSE, never NA. All four use inherits(x, "list") as their entry test, so an object that fails that test returns FALSE.

Documentation

Full reference and articles live at https://niphr.github.io/csutil/.

Read the introduction vignette, or run help(package="csutil").