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

1,833

Version

1.8.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Hugh Parsonage

Last Published

April 13th, 2022

Functions in hutils (1.8.1)

bearing

Bearing calculations
RQ

Shorthand for requireNamespace
all_same_sign

Determine whether a vector is all of the same sign
auc

AUC
aliases

Aliases
Switch

Vectorized switch
average_bearing

Average of bearings
any_grepl

Does the pattern appear anywhere?
Mode

Statistical mode
coalesce

Find first non-missing element
dir2

List many files
drop_colr

Drop columns whose names match a pattern
provide.dir

Provide directory
drop_col

Drop column or columns
%notchin%

Negation of in (character)
%notin%

Negation of in
provide.file

Provide a file
set_cols_first

Put columns first or last
seq_nrow

Generate sequence of row numbers
weight2rows

Expand a weighted data frame to an equivalent unweighted
dev_copy2a4

Copy device to an A4 PDF
weighted_ntile

Weighted (ranked) quantiles
implies

#' Logical implies
mutate_other

Group infrequent entries into 'Other category'
isAttached

Is a package attached?
drop_constant_cols

Drop constant columns
ngrep

Anti-grep
replace_pattern_in

Replace string pattern in text file
drop_empty_cols

Drop empty columns
%ein%

Exists and (not) in
find_pattern_in

Find string pattern in (text) file
report_error

Report errors and warnings
ahull

Maximum area given x and y coordinates
if_else

Vectorized if
hutils-package

hutils package
isTrueFalse

Logical assertions
samp

Safer sampler
select_grep

Select names matching a pattern
weighted_quantile

Weighted quantile
longest_affix

Longest common prefix/suffix
duplicated_rows

Return duplicated rows of data.table
fst_columns

Utilities for `fst` files
generate_LaTeX_manual

Generate LaTeX manual of installed package
mean_na

Proportion of values that are NA.
%pin%

Partial in
haversine_distance

Distance between two points on the Earth
mutate_ntile

Add a column of ntiles to a data table
prohibit_unequal_length_vectors

Prohibit unequal length vectors
prohibit_vector_recycling

Prohibit vector recycling
selector

Fast selection of data.table columns
select_which

Select columns satisfying a condition
swap

Swap assignment
unique-keys

Unique keys