Title: Base Functions for the DescToolsX Ecosystem
License: GPL (โฅ 2)
๐งฉ Overview
bedrock is the foundation layer of the DescToolsX ecosystem. It provides low-level, generic utilities and basic routines โ data manipulation, inspection, vector operations, string handling, math and combinatorics โ that serve as building blocks for the higher-level statistical, graphics, and modelling packages of the suite.
The package is self-contained. It has no dependency on any other package of the suite and is equally useful on its own.
It follows the DescToolsX design rules: a consistent lowerCamelCase API, generic functions with S3 methods, predictable argument names and ordering, and performance-critical routines implemented in Rcpp.
๐ Documentation: https://andrisignorell.github.io/bedrock/
โ๏ธ Installation
Install the released version from CRAN:
install.packages("bedrock")Or the development version from GitHub:
remotes::install_github("AndriSignorell/bedrock")๐ Core Features
๐น Data Manipulation
Appending, recoding, renaming, sorting, and reshaping of vectors, factors, matrices, and data frames.
-
appendX(),appendRowNames(),appendEnum() -
recodeX(),revCode(),combLevels(),dummy() -
sortX(),revX(),renameX(),setNamesX() -
splitX(),splitAt(),toLong()/toWide() -
recycle(),columnWrap(),compareDataFrames() -
toBaseR(),stringsAsFactors() - Type coercion shortcuts:
num(),int(),chr(),nchr(),bin()
๐น Data Inspection & Validation
Predicates and checks for data quality and structure.
-
isNumeric(),isDichotomous(),isLowCardinality(),isWholeLike(),isZero(),isNA() -
allDuplicated(),allIdentical(),completeColumns(),countCompCases(),flags() - Between operators:
%[]%,%()%,%[)%,%(]% -
isFilePath(),isURL(),isEuclid()
๐น Mathematical Functions
-
roundTo(),linScale(),logit() -
nDec(),prec(),frac(),maxDigits() -
rankX(),percentRank(),nUnique() -
dotProd(),crossProd(),crossProdN() -
unirootAll(),untable()
๐น Number Theory & Combinatorics
-
primes(),isPrime(),factorize(),divisors() -
GCD()/LCM(),fibonacci(),digitSum(),isOdd() - Base conversions:
decToBin(),decToHex(),decToOct(),baseToBase(),romanToInt() -
combN(),combSet(),combPairs(),permn() -
sampleX(),randGroupSplit(),unwhich()
๐น Labels & Metadata
-
label()โ get or set variable labels -
setAttr(),removeAttr(),keepAttr() -
openDataObject(),dataDescription()โ Excel data with codes and labels
๐น File Utilities
-
buildPath(),splitPath() -
findDownload(),readDownload(),peekFile() -
fileExistURL(),pdfManual() -
parseSASDatalines()โ parse SAS DATALINES blocks into a data.frame
๐น Datasets
Teaching and example datasets: Cards, Pizza, Roulette, Tarot, plus courseData() for loading course material.
๐ Design Principles
- Consistent โ lowerCamelCase API and uniform argument conventions across the whole DescToolsX suite
- Fast โ performance-critical routines implemented in Rcpp
- Generic โ S3 generics with methods for vectors, factors, matrices, tables, and data frames
- Robust โ validated inputs, informative errors, extensive testthat coverage
๐งช Example
library(bedrock)
# range operators
x <- 1:10
x %[]% c(3, 6)
# first non-missing value
coalesceX(c(NA, NA, 5, 3))
# round to arbitrary multiples
roundTo(c(1.23, 4.56), 0.25)
# all 2-element subsets
combSet(letters[1:4], 2)
# parse a SAS data step
sas <- "
data mydata;
input name $ age score;
datalines;
Alice 30 95.5
Bob 25 88.0
;
"
parseSASDatalines(sas)