Learn R Programming

⚠️There's a newer version (1.2.15) of this package.Take me there.

omnibus

R Utility Functions for the 99%

An assortment of helper functions for managing data (e.g., rotating values in matrices by a user-defined angle, switching from row- to column-indexing), dates (e.g., intuiting year from messy date strings), handling missing values (e.g., removing elements/rows across multiple vectors or matrices if any have an NA), text (e.g., flushing reports to the console in real-time); and combining data frames with different schema (copying, filling, or concatenating columns or applying functions before combining).

Installation

As of version 1.1.2, omnibus is on CRAN! You can install the latest CRAN-stable version the normal way you install packages from CRAN, or the development version by using:

remotes::install_github('adamlilith/omnibus', dependencies=TRUE)

You may need to install the remotes package first.

Data manipulation

  • appendLists(): Merge lists, appending elements with the same name.
  • bracket(): Find values that bracket a given number.
  • combineDf(): Combine data frames with different schema.
  • compareFloat(): Compare two values to within floating-point precision.
  • convertUnits(): Convert length or areal units.
  • conversionFactors(): Data frame of conversion factors for length or areal units.
  • corner(): Corner of a matrix or data frame.
  • cull(): Force vectors or matrices/data frames to have the same length or number of rows.
  • expandUnits(): Convert unit abbreviations to proper unit names.
  • insert(): Insert values into a vector.
  • insertCol and insertRow(): Insert column(s)/row(s) in a matrix or data frame.
  • maxRuns(): Maximum number of continuous "runs" of values meeting a particular condition.
  • mergeLists(): Merge lists, with precedence for elements of one list over another if they have the same names.
  • mirror(): Flip an object left-right (or up-down).
  • mmode(): Modal value(s).
  • notIn() and %notin%: Opposite of %in%.
  • renameCol(): Rename a column.
  • renumSeq(): Renumber a sequence.
  • rotateMatrix(): Rotate a matrix.
  • roundTo(): Rounds a value to the nearest target value.
  • rowColIndexing(): Convert between row and column indexing of a matrix.
  • side(): Left/right side of a data frame or matrix.
  • stretchMinMax(): Rescale values to a given range.
  • unlistRecursive(): For any object in a list that is also a list, unlist it.
  • unragMatrix(): Turn a "ragged" matrix into a "ragged" vector.

Dates

  • domLeap(): Data frame of days of each month in a leap year.
  • domNonLeap(): Data frame of days of each month in a non-leap year.
  • doyLeap(): Data frame of days of year in a leap year.
  • doyNonLeap(): Data frame of days of year in a non-leap year.
  • isLeapYear(): Is a year a leap year?
  • yearFromDate(): Attempt to find the year across dates with non-standard formats.

Geometry

  • pairDist(): Pairwise Euclidean distance between two sets of points.
  • quadArea(): Area of a quadrilateral.

Handling NAs

  • %<na%, %<=na%, %==na%, %!=na%, %>na%, and %>=na%: Comparative operations (>, >=, ==, !=, <, <=) but returns FALSE for NA cases (versus NA).
  • isTRUENA and isFALSENA(): Logical operators robust to NA.
  • naCompare(): Comparative operations (>, >=, ==, !=, <, <=) but returns FALSE for NA cases (versus NA).
  • naOmitMulti(): Remove elements of multiple vectors if at least one element is NA or rows of matrices/data frames if at least one row has an NA.
  • naRows(): Indices of rows with at least one NA.

Data properties

  • countDecDigits(): Count number of digits after a decimal.
  • is.wholeNumber(): Is a numeric value a whole number, to within floating-point precision?
  • longRun(): Longest run of a given sequence in a vector.
  • roundedSigDigits(): Infers the number of significant digits represented by a decimal representation of a division operation or digits place to which an integer was rounded.
  • which.pmax and which.pmin(): Combine which.max with pmax and which.min with pmin (vectorized which.max and which.min).

System

  • dirCreate(): Nicer version of dir.create().
  • eps(): Smallest floating point value your computer can think of.
  • listFiles(): Nicer version of list.files().
  • memUse(): Display largest objects in memory.

Text

  • capIt(): Capitalize first letter of a string.
  • forwardSlash(): Convert backslashes to forward slashes.
  • pmatchSafe(): Partial matching of strings with error checking.
  • prefix(): Add repeating character to a string to ensure it has a user-defined length (e.g., 7 --> 007).
  • rstring(): Make a nearly-guaranteed unique string.
  • say(): Replacement for print('abc'); flush.console().

Adam

Copy Link

Version

Install

install.packages('omnibus')

Monthly Downloads

705

Version

1.2.14

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Adam B. Smith

Last Published

September 17th, 2024

Functions in omnibus (1.2.14)

domNonLeap

Day of month for non-leap years
corner

Corner of a matrix or data frame
doyLeap

Day of year for leap years
cull

Force objects to have length or rows equal to the shortest
ellipseNames

Get names of objects input as arguments in ellipse (...) form
doyNonLeap

Days of year for non-leap years
eps

The smallest machine-readable number
isLeapYear

Is a year a leap year?
isTRUENA

Vectorized test for truth robust to NA
expandUnits

Convert unit abbreviations to proper unit names
dirCreate

Replacement for dir.create()
memUse

Size of objects taking most memory use
maxRuns

Maximum number of continuous "runs" of values meeting a particular condition
domLeap

Day of month for leap years
mergeLists

Merge two lists with precedence
forwardSlash

Replace backslash with forward slash
combineDf

Combine data frames with different fields using a crosswalk table
insert

Insert values into a vector
listFiles

Replacement for list.files()
insertCol

Insert a column or row into a data frame or matrix
longRun

Length of the longest run of a particular value in a numeric vector
mmode

Modal value(s)
mirror

Flip an object
notIn

Opposite of '%in%'
prefix

Add leading characters to a string
naOmitMulti

Remove NAs from one or more equal-length vectors
is.wholeNumber

Test if a numeric value is a whole number
naCompare

Compare values using <, <=, >, >=, !=, and == (robust to NAs)
omnibus

omnibus: Fantabulous helper functions
rowColIndexing

Convert between row- and column-style indexing of matrices
pmatchSafe

Partial matching of strings with error checking
naRows

Index of rows in a data frame or matrix that contain at least one NA
renameCol

Rename columns
quadArea

Area of a quadrilateral
pairDist

Calculate pairwise distances between two matrices or data frames.
roundedSigDigits

Number of significant digits in rounded numbers
renumSeq

Renumber a sequence of numbers
rotateMatrix

Rotate values in a matrix
rstring

Make a nearly-guaranteed unique string
side

Left/right side of a data frame or matrix
say

Nicer version of print() or cat() function
which.pmax

Which vector has maximum value at each element
unragMatrix

Turn a "ragged" matrix into a "ragged" vector
roundTo

Round to nearest target value
stretchMinMax

Rescale values
unlistRecursive

For any object in a list that is also a list, unlist it
yearFromDate

Year from date formats that are possibly ambiguous
conversionFactors

Data frame or conversion factors for length or areal units
bracket

Identify values bracketing another value
convertUnits

Convert length or areal units
appendLists

Append values to elements of a list from another list
compareFloat

Compare values to floating-point precision
countDecDigits

Number of digits after a decimal place
capIt

Capitalize first letter of a string