Skip to contents

CRAN CRAN License: GPL v3 R-CMD-check.yaml Coverage Status downloads kit status badge

Fast data manipulation functions implemented in C for large datasets. Provides vectorized alternatives to base R functions with significant performance improvements.

Installation

# From CRAN
install.packages("kit")

# Development version
install.packages("kit", repos = "https://fastverse.r-universe.dev")

Features

Parallel Statistical Functions

Vector-valued functions operating in parallel over vectors or data frames:

  • psum, pprod, pmean: Parallel sum, product, and mean (similar to pmin/pmax)
  • pall, pany: Parallel all/any operations
  • pcount, pcountNA: Count occurrences of values or NAs
  • pfirst, plast: First/last non-missing values
x <- c(1, 3, NA, 5)
y <- c(2, NA, 4, 1)
psum(x, y, na.rm = TRUE)  # [1] 3 3 4 6
pmean(x, y, na.rm = TRUE) # [1] 1.5 3.0 4.0 3.0

Vectorized and Nested Switches

Fast vectorized conditional logic:

  • iif: Fast replacement for ifelse() with attribute preservation
  • nif: Nested if-else (SQL CASE WHEN equivalent)
  • vswitch, nswitch: Vectorized switch statements
iif(x > 2, x, x - 1)  # Preserves attributes unlike base::ifelse
nif(x == 1, "one", x == 2, "two", default = "other")

Sorting

  • psort: Parallel sort for character vectors
  • topn: Efficient partial sort (top N values) without full sorting
topn(x, n = 6L, decreasing = TRUE)  # Much faster than order()[1:6]

Factors

  • charToFact: Fast character-to-factor conversion
  • setlevels: Change factor levels by reference

Unique Values and Counts

  • funique, fduplicated: Fast unique/duplicated operations
  • uniqLen: Fast equivalent to length(unique(x))
  • count, countNA, countOccur: Count element occurrences
funique(iris$Species)  # Faster than base::unique
uniqLen(iris$Species)  # Faster than length(unique())

Miscellaneous

  • fpos: Find matrix/vector positions within larger structures
  • shareData, getData, clearData: Share data between R sessions

Documentation

Full documentation available at: https://fastverse.github.io/kit/

License

GPL-3