Learn R Programming

⚠️There's a newer version (2.0.0) 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

2,923

Version

1.5.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Hugh Parsonage

Last Published

October 5th, 2019

Functions in hutils (1.5.1)

coalesce

Find first non-missing element
drop_colr

Drop columns whose names match a pattern
longest_affix

Longest common prefix/suffix
average_bearing

Average of bearings
select_grep

Select names matching a pattern
drop_col

Drop column or columns
samp

Safer sampler
isTrueFalse

Logical assertions
ngrep

Anti-grep
set_cols_first

Put columns first or last
all_same_sign

Determine whether a vector is all of the same sign
aliases

Aliases
swap

Swap assignment
Mode

Statistical mode
duplicated_rows

Return duplicated rows of data.table
%ein%

Exists and (not) in
find_pattern_in

Find string pattern in (text) file
RQ

Shorthand for requireNamespace
isAttached

Is a package attached?
implies

#' Logical implies
mean_na

Proportion of values that are NA.
mutate_ntile

Add a column of ntiles to a data table
select_which

Select columns satisfying a condition
selector

Fast selection of data.table columns
unique-keys

Unique keys
hutils-package

hutils package
drop_constant_cols

Drop constant columns
drop_empty_cols

Drop empty columns
weight2rows

Expand a weighted data frame to an equivalent unweighted
generate_LaTeX_manual

Generate LaTeX manual of installed package
%pin%

Partial in
provide.dir

Provide directory
if_else

Vectorized if
provide.file

Provide a file
haversine_distance

Distance between two points on the Earth
replace_pattern_in

Replace string pattern in text file
report_error

Report errors and warnings
weighted_ntile

Weighted (ranked) quantiles
weighted_quantile

Weighted quantile
ahull

Maximum area given x and y coordinates
Switch

Vectorized switch
any_grepl

Does the pattern appear anywhere?
dev_copy2a4

Copy device to an A4 PDF
dir2

List many files
%notchin%

Negation of in (character)
auc

AUC
%notin%

Negation of in
mutate_other

Group infrequent entries into 'Other category'