Base Functions for the 'DescToolsX' Ecosystem

Provides the low level utilities on which the 'DescToolsX' ecosystem is built. Covered are data manipulation and reshaping, predicates for data inspection and validation, vector and string operations, handling of labels and metadata, and routines from number theory and combinatorics. All functions share a common naming and argument scheme and are implemented as S3 generics wherever several input types are meaningful, with performance critical parts written in C++. The package is self contained and can be used on its own, independently of the higher level packages of the suite.


๐Ÿ“ฆ bedrock bedrock logo

CRAN status R-CMD-check Codecov test coverage Downloads License: GPL v2

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()

๐Ÿ”น Vector Operations

  • coalesceX(), closest(), locf()
  • naIf(), naReplace(), nz()
  • trim(), winsorize(), setLength()
  • moveAvg(), midx(), vRot(), vShift(), pairApply()

๐Ÿ”น String Utilities

  • mGsub(), mReplace()
  • strSplitToCol(), strSplitToDummy()
  • charToAscii() / asciiToChar(), asCDateFmt()

๐Ÿ”น 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()

๐Ÿ”น Tables & Merging

  • collapseTable(), multMerge(), printCharMatrix()

๐Ÿ”น 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()
  • urlExists(), pdfManual()
  • parseSasDatalines() โ€” parse SAS DATALINES blocks into a data.frame

๐Ÿ”น Programming & Introspection

  • callIf(), mergeArgs(), extractArgs(), getDotsArg(), quot()
  • resolveFormula(), resolveGroups(), resolveContingency()
  • funArgs(), funCalls(), funList(), funKeywords()
  • rdTitle(), rdLabels(), strX()

๐Ÿ”น Datasets

Teaching and example datasets: Cards, Pizza, Roulette, Tarot, plus readCourseData() 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)

๐Ÿ™ Acknowledgements

Parts of the code and documentation were reviewed with the help of large language models (OpenAI Codex, Anthropic Claude). Every suggestion was assessed, edited and verified by the maintainer, who remains solely responsible for the content of this package.

๐Ÿ“œ License

GPL (โ‰ฅ 2)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("bedrock")

0.1.20 by Andri Signorell, 4 days ago


https://andrisignorell.github.io/bedrock/, https://github.com/AndriSignorell/bedrock/


Report a bug at https://github.com/AndriSignorell/bedrock/issues


Browse source code at https://github.com/cran/bedrock


Authors: Andri Signorell [aut, cre] (ORCID: , R Core Team [ctb] , Hans W. Borchers [ctb] , Daniel Chessel [ctb] , Nicholas Cooper [ctb] , Stephane Dray [ctb] , Martin Elff [ctb] , Michael Friendly [ctb] , Friedrich Leisch [ctb] , Thomas Lumley [ctb] , Martin Maechler [ctb] , Nick Sabbe [ctb] , Karline Soetaert [ctb] , Terry Therneau [ctb] , Kevin Ushey [ctb] , Jeremy VanDerWal [ctb] , Bill Venables [ctb] , Gregory R. Warnes [ctb] , Daniel Wollschlaeger [ctb] , Thomas W. Yee [ctb]


Documentation:   PDF Manual  


GPL (>= 2) license


Imports Rcpp, abind, expm, tools, data.table, readxl, httr, cli

Suggests testthat, haven, R.rsp, readr, tibble

Linking to Rcpp


See at CRAN