Learn R Programming

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

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,932

Version

1.5.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Hugh Parsonage

Last Published

May 31st, 2019

Functions in hutils (1.5.0)

aliases

Aliases
coalesce

Find first non-missing element
auc

AUC
any_grepl

Does the pattern appear anywhere?
average_bearing

Average of bearings
all_same_sign

Determine whether a vector is all of the same sign
drop_constant_cols

Drop constant columns
%ein%

Exists and (not) in
duplicated_rows

Return duplicated rows of data.table
%notchin%

Negation of in (character)
drop_empty_cols

Drop empty columns
implies

#' Logical implies
isAttached

Is a package attached?
dev_copy2a4

Copy device to an A4 PDF
%pin%

Partial in
dir2

List many files
provide.dir

Provide directory
replace_pattern_in

Replace string pattern in text file
RQ

Shorthand for requireNamespace
generate_LaTeX_manual

Generate LaTeX manual of installed package
set_cols_first

Put columns first or last
samp

Safer sampler
hutils-package

hutils package
%notin%

Negation of in
if_else

Vectorized if
find_pattern_in

Find string pattern in (text) file
select_grep

Select names matching a pattern
swap

Swap assignment
drop_col

Drop column or columns
isTrueFalse

Logical assertions
longest_affix

Longest common prefix/suffix
mutate_other

Group infrequent entries into 'Other category'
drop_colr

Drop columns whose names match a pattern
select_which

Select columns satisfying a condition
ngrep

Anti-grep
selector

Fast selection of data.table columns
mean_na

Proportion of values that are NA.
haversine_distance

Distance between two points on the Earth
provide.file

Provide a file
mutate_ntile

Add a column of ntiles to a data table
weighted_ntile

Weighted (ranked) quantiles
weighted_quantile

Weighted quantile
unique-keys

Unique keys
report_error

Report errors and warnings
weight2rows

Expand a weighted data frame to an equivalent unweighted
ahull

Maximum area given x and y coordinates
Switch

Vectorized switch
Mode

Statistical mode