Skip to content

Repository files navigation

shrt

Functions for shorter R code

Statuscodecov

Introduction

Some commands or sequences of commands occur so often that one can wish for shorthand notation. This package is a collection of such shorthand functions.

For example, writing tab-separated tables with headers requires calling write.table() with options quote=F, col.names=T, row.names=F, sep='\t'. This package implements a function wtht() that achieves these common settings by default and thus shortens code substantially.

Many of the function in this package are similar to wtht() in that they are relatively simple wrappers for existing R functions. Some of the functions, including wtht, also include features that would otherwise have to be written using two or more commands (see documentation).

Disclaimer: Useful shorthand notation is subjective. Thus you might not agree with all acronyms or design choices in these functions. So please feel free to use/adapt just bits and pieces from the package.

Contents

The following is a quick synopsis of the functions available in the package. Column Group provides a category for each function and helps to identify where to find the code and documentation. Column Function shows the function names.

GroupFunctionDescription
cacheassigncassign to variable using value from cache
cachecachedirset a directory to act as a disk cache
cachecachefileget path to a file in cache
cachecacheprefixset a prefix for cache files
cacheexistsccheck if cache contains representation for a variable
cacheloadcload object from cache
cachermcremove an object from environment and from cache
cachesavecsave an oject into disk cache
colorsx2hexmap values into a hex transparency code
colorsx2colmap vectors or matrices onto a 2-color scale
datajijaccard index of two sets
dataoioverlap index of two sets
datasetsummarysummary of set membership
filesload1load from Rdata file into one named object
filesloaddirload content from a directory
filesrthtread tables from files
fileswthtwrite tables to files
loopsapwiapply with iterator index
messagesmsglog and output a message
messagesnewmsgcreate message logger
plotlimqevaluate pretty limits for axes using quantiles
plotwidenupdate an range to make wider
projectsinitpinitiate directories/folders for a project
projectsreqvarscheck whether variables are defined
utilscatvprint to console, but only in verbose mode
utilsemptyevaluate if object is of zero length
utilsgrepfpattern matching inside text files (file search)
utilsgrepvpattern matching returning values
utilsh1, h2, h3head with preset n
utilslengrepnumber of hits in a grep search
utilslenunumber of unique elements
utilslinecharscount number of characters per line inside text files
utilslstcollect objects into a named list
utilsmtrxcreating matrices
utilsnamesFget elements with value FALSE
utilsnamesNAget elements with value NA
utilsnamesTget elements with value TRUE
utilsnamesVget elements with given value(s)
utilsnewvcreate empty, named vectors
utilsnlistcreate a named list from a vector or data frame
utilsnveccreate named vector from a data frame
utilsp0paste0
utilspluckextract a component from an object or list
utilspluck1extract first components from a list of objects
utilspluck2extract second components from a lit of objects
utilstodaycreate a string with current date
utilsx2dftransform objects into data frames

Documentation

Documentation on each function (or each family of functions) is available through markdown vignettes.

License

The package is under a MIT license. Comments and contributions are welcome.

About

Functions for short R code

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages