1 Tidylog

The goal of tidylog is to provide feedback about dplyr and tidyr operations. It provides simple wrapper functions for the most common functions, such as filter, mutate, select, full_join, and group_by.

https://github.com/elbersb/tidylog


1.1 Example


Tidylog will give you feedback, for instance when filtering a data frame or adding a new variable:

## filter: removed 21 rows (66%), 11 rows remaining
## mutate: new variable 'new_var' with 29 unique values and 0% NA

Tidylog reports detailed information for joins:

## left_join: added 9 columns (temp, dewp, humid, wind_dir, wind_speed, …)
##            > rows only in x     1,556
##            > rows only in y  (  6,737)
##            > matched rows     335,220
##            >                 =========
##            > rows total       336,776

Tidylog can be especially helpful in longer pipes:

## select: dropped 7 variables (disp, drat, wt, qsec, vs, …)
## filter: removed 6 rows (19%), 26 rows remaining
## mutate: new variable 'mpg_round' with 15 unique values and 0% NA
## group_by: 3 grouping variables (cyl, mpg_round, am)
## tally: now 20 rows and 4 columns, 2 group variables remaining (cyl, mpg_round)
## filter (grouped): no rows removed

1.2 More examples

1.2.1 filter, distinct, drop_na

## filter: removed 18 rows (56%), 14 rows remaining
## filter: removed all rows (100%)
## filter: no rows removed
## filter_at: removed 19 rows (59%), 13 rows remaining
## distinct: no rows removed
## distinct_at: removed 18 rows (56%), 14 rows remaining
## top_n: removed 19 rows (59%), 13 rows remaining
## drop_na: removed 42 rows (27%), 111 rows remaining
## drop_na: removed 37 rows (24%), 116 rows remaining
## drop_na: no rows removed

1.2.2 mutate, transmute, replace_na, fill

## mutate: new variable 'new_var' with one unique value and 0% NA
## mutate: new variable 'new_var' with 32 unique values and 0% NA
## mutate: new variable 'new_var' with one unique value and 100% NA
## mutate_at: changed 28 values (88%) of 'mpg' (0 new NA)
##            changed 31 values (97%) of 'drat' (0 new NA)
## mutate: new variable 'am_factor' with 2 unique values and 0% NA
## mutate: converted 'am' from double to factor (0 new NA)
## mutate: changed 13 values (41%) of 'am' (13 new NA)
## mutate: converted 'am' from double to character (13 new NA)
## transmute: dropped 9 variables (cyl, disp, hp, drat, wt, …)
##            changed 32 values (100%) of 'mpg' (0 new NA)
##            changed 32 values (100%) of 'gear' (0 new NA)
##            new variable 'new_var' with 3 unique values and 0% NA
## replace_na: converted 'Solar.R' from integer to double (7 fewer NA)
## fill: changed 37 values (24%) of 'Ozone' (37 fewer NA)

1.2.3 joins

For joins, tidylog provides more detailed information. For any join, tidylog will show the number of rows that are only present in x (the first dataframe), only present in y (the second dataframe), and rows that have been matched. Numbers in parantheses indicate that these rows are not included in the result. Tidylog will also indicate whether any rows were duplicated (which is often unintentional):

## left_join: added one column (b)
##            > rows only in x   0
##            > rows only in y  (0)
##            > matched rows     3    (includes duplicates)
##            >                 ===
##            > rows total       3
## full_join: added one column (plays)
##            > rows only in x   1
##            > rows only in y   1
##            > matched rows     2
##            >                 ===
##            > rows total       4
## anti_join: added no columns
##            > rows only in x   1
##            > rows only in y  (1)
##            > matched rows    (2)
##            >                 ===
##            > rows total       1

1.2.4 select

## select: dropped 9 variables (cyl, disp, hp, drat, qsec, …)
## select: dropped 7 variables (mpg, cyl, disp, hp, wt, …)
## select_if: dropped all variables

1.2.5 summarize

## group_by: 2 grouping variables (cyl, carb)
## summarize: now 9 rows and 3 columns, one group variable remaining (cyl)

1.2.6 tally, count, add_tally, add_count

## group_by: 2 grouping variables (gear, carb)
## tally: now 11 rows and 3 columns, one group variable remaining (gear)
## group_by: 2 grouping variables (gear, carb)
## add_tally (grouped): new variable 'n' with 5 unique values and 0% NA
## count: now 11 rows and 3 columns, ungrouped
## add_count: new variable 'count' with 5 unique values and 0% NA

1.2.7 gather, spread

## mutate: new variable 'id' with 32 unique values and 0% NA
## gather: reorganized (mpg, cyl, disp, hp, drat, …) into (col, data) [was 32x12, now 352x3]
## spread: reorganized (col, data) into (am, carb, cyl, disp, drat, …) [was 352x3, now 32x12]