Learn R Programming

hutils

Miscellaneous R functions and aliases

My name is Hugh and this is a package of functions I often put in R/utils.s. Hence, hutils.

Scope

The package attempts to provide lightweight, fast, and stable functions for common operations.

By lightweight, I mean in terms of dependencies: we import package:data.table and package:fastmatch which do require compilation, but in C. Since so many operations handle data frames, data.table seemed worthwhile -- and besides its compile time is not too onerous. Otherwise, all dependencies do not require compilation. (I also try to minimize the cardinality of package imports, but it's mostly the compile time I'm focused on.)

By fast, I mean essentially as fast as possible without using compilation.

By stable, I mean that unit tests should not change unless the major version also changes. To make this completely transparent, tests include the version of their introduction and are guaranteed to not be modified (not even in the sense of adding extra, independent tests) while the major version is 1. Tests that do not include the version in their filename may be modified from version to version (though this will be avoided).

Copy Link

Version

Install

install.packages('hutils')

Monthly Downloads

5,910

Version

2.0.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Hugh Parsonage

Last Published

January 18th, 2026

Functions in hutils (2.0.0)

hutils-package

hutils package
duplicated_rows

Return duplicated rows of data.table
%pin%

Partial in
prohibit_vector_recycling

Prohibit vector recycling
selector

Fast selection of data.table columns
samp

Safer sampler
prohibit_unequal_length_vectors

Prohibit unequal length vectors
provide.dir

Provide directory
select_grep

Select names matching a pattern
provide.file

Provide a file
if_else

Vectorized if
select_which

Select columns satisfying a condition
swap

Swap assignment
ngrep

Anti-grep
mutate_other

Group infrequent entries into 'Other category'
unique-keys

Unique keys
%notin%

Negation of in
dir2

List many files
drop_col

Drop column or columns
%notchin%

Negation of in (character)
isTrueFalse

Logical assertions
drop_colr

Drop columns whose names match a pattern
weighted_quantile

Weighted quantile
implies

#' Logical implies
drop_constant_cols

Drop constant columns
isAttached

Is a package attached?
longest_affix

Longest common prefix/suffix
mean_na

Proportion of values that are NA.
mutate_ntile

Add a column of ntiles to a data table
haversine_distance

Distance between two points on the Earth
replace_pattern_in

Replace string pattern in text file
report_error

Report errors and warnings
weight2rows

Expand a weighted data frame to an equivalent unweighted
set_cols_first

Put columns first or last
seq_nrow

Generate sequence of row numbers
weighted_ntile

Weighted (ranked) quantiles
Mode

Statistical mode
Switch

Vectorized switch
auc

AUC
any_grepl

Does the pattern appear anywhere?
aliases

Aliases
bearing

Bearing calculations
average_bearing

Average of bearings
all_same_sign

Determine whether a vector is all of the same sign
ahull

Maximum area given x and y coordinates
RQ

Shorthand for requireNamespace
coalesce

Find first non-missing element
find_pattern_in

Find string pattern in (text) file
dev_copy2a4

Copy device to an A4 PDF
%ein%

Exists and (not) in
fst_columns

Utilities for `fst` files
drop_empty_cols

Drop empty columns
generate_LaTeX_manual

Generate LaTeX manual of installed package