short

Build Status

library(short)

Overview

The short package gives several shortcuts to common functionality.

using - easy loading packages

The using function is a simpler way of specifying multiple packages to load. It additionally will attempt to download and install the packages if not already installed.

table_1 - Table 1 Demographics and Summaries

The table_1 function can be used to generate a demographics and summary of variables; i.e. the veritable "Table 1" for publications. For each variable given, table_1 calls summarise_table_1 which will summarize the variable for each value of a key, differentiating variable, as well as overall. For character and factor variables, the counts and percentages of each level is given. For logical variables, the count of positives and the percentage is given as the value. Numeric Variables are summarized by the minimum, median, mean, maximum, and standard deviation.

Additional methods for table_1 can be added by adding methods to summarise_table_1

Example

library(tidyverse)
mtcars %>% 
    mutate( gear = ordered(paste(gear, 'Gears'))
          , cyl  = ordered(paste(cyl, 'Cylinders'))
          ) %>% 
    table_1( cyl
           , 'Automatic Transmission' = am == 0
           , 'Number of gears' = gear
           , Horsepower = hp
           )

with_margins - add marginals to and computation.

The with_margins function converts another function to operate over all possible subsets of groups, including no groups.

Example

mtcars %>% 
    mutate( gear = ordered(paste(gear, 'Gears'))
          , cyl  = ordered(paste(cyl, 'Cylinders'))
          ) %>%
    group_by(gear, cyl) %>% 
    with_margins(summarise_at)( vars(mpg, disp, hp, wt)
                              , funs(min, mean, max)
                              )

spread_each - Spread Multiple Values

The spread_each function works similar to the tidyr::spread function but works for spreading out multiple values.

Example

mtcars %>% 
    count(gear, cyl) %>% 
    group_by(gear) %>%
    mutate(pct = n/sum(n)) %>% 
    spread_each(cyl, n, pct)

.T - Simple text specification

Similar to lazy loading of the tidyverse, the .T function provides a simple way to designate arguments should be interpreted as text. The limiting factor is that the text must be syntactically correct, however it come in very helpful.

Example

.T(first, second, 'a third argument with spaces')

Inline functions

The short package also provides many inline shortcuts.

Text concatenations

Pattern Matching

Other

String Filtering

There are two convenience function for filtering character vectors, sift and the filter out version seive.

# limit to Mercs
mtcars %>% rownames() %>% sift("^Merc")
# Filter out everything starting with M
mtcars %>% rownames() %>% sieve("^M")


halpo/short documentation built on July 18, 2019, 12:06 a.m.