A very tidy advent 2022

A very tidy advent 2022

25 days of tidyverse and r-lib functions, tips, and tricks.

fs::dir_ls() written in monospaced font on pink background.

Day 20: fs::dir_ls()
3 min
Equivalent to the ls command, dir_ls() returns filenames as a named character vector of fs_paths, making it perfect for passing into the .id argument of…
2022-12-20

Code reads: year_month_weekday(year = 2023, month = clock_months$november, day = clock_weekdays$thursday, index = 4). Next to it is a calendar for November with the fourth Thursday circled.

Day 19: year_month_weekday()
2 min
Get the nth occurrence of a given weekday in a month with clock’s year_month_weekday() function.
2022-12-19

Teal rectangle that says brio above Basic R Input Output.

Day 18: brio
2 min
brio (short for Basic R Input Output) provides functions to do just that–handle basic input output in R. Its functions always read and write UTF-8 files, and provide more…
2022-12-18

curly curly written in cursive above a pair of double curly braces that have stars on the ends of each brace.

Day 17: rlang’s {{ }}
2 min

Wrap function arguments containing data-frame variables in rlang’s embracing operator ({{) for simpler tidy eval of “data-masked” arguments in functions.

2022-12-17

rbind_pages(list()) written with three light pink data-frame icons in between the list parentheses. A downward arrow leads to a larger, darker pink data-frame icon.

Day 16: rbind_pages()
2 min

Got paginated JSON data? The rbind_pages() function from Jeroen Ooms’ jsonlite package is here to save the day.

2022-12-16

hms package hexagon logo on a light green background.

Day 15: hms
2 min

A simple class for durations or time-of-day values, hms lets you construct and work with hours, minutes, and seconds.

2022-12-15

c_across() written in black against a blue background with slight white stripes.

Day 14: c_across()
3 min

Designed to work with rowwise(), c_across() uses tidyselect semantics to make it easier to perform row-wise aggregations.

2022-12-14

Below error message (Error in rowMeans(mini_dat): &#039;x' must be an array of at least two dimensions) rlang::last_trace() is run. The output produced shows <error/rlang_error> in blue at the top, followed by Error (in yellow) with the error message printed. Lastly, there is a Backtrace. It is a tree with a box with numbered elements below it: 1. global fruit_avg(dat, pattern = 'black'), 2. base::rowMeans(mini_dat) at 2022-tidyverse-advent/R/fruit_avg.R:8:2. The file path is an interactive link.

Day 13: rlang::entrace
4 min
Promote base R errors to rlang errors and get simplified backtraces with options(error = rlang::entrace) and rlang::last_trace().
2022-12-13

Code cell on left that has glue in curly braces next to backticks, body of which reads 1 + 1 = {1 + 1}. An arrow indicates that the output is to its right. The output reads 1 + 1 = 2.

Day 12: glue’s knitr engine
2 min

Use glue’s custom knitr language engine to evaluate chunk contents as a glue template.

2022-12-12

library(gert) followed by output in slightly lighter shade that reads: Linking to libgit2 v1.4.2, ssh support: YES; Global config: /Users/maraaverick/.gitconfig; Default user: Mara Averick &lt;myemailname@email.com>.

Day 11: gert
2 min

A minimal Git client for R, the beauty of gert lies in the fact that it gets user credentials through your command-line git credentials store.

2022-12-11

Terminal window showing the output of rig list (a table of with name, version, and aliases for installed r versions), and rig default (the default version of R on the machine, 4.2-arm64).

Day 10: rig
2 min

Install, remove, and configure R versions on your machine with rig: the R installation manager.

2022-12-10

purrr::pluck() written on light green background in the style of a marker.

Day 09: pluck()
5 min
A generalized form of [[, pluck() lets you safely get an element from deep within a nested data structure (and its friend chuck() does the same, but errors if it isn’t…
2022-12-09

str_squish() is wrapped around a string with dots indicating trailing and leading white space and several internal spaces between words, an arrow shows that the output will have no leading or trailing white space and the internal spaces will be reduced to single spaces between words.

Day 08: str_squish()
2 min

Remove trailing, leading, and excess white space in the middle with stringr’s str_squish().

2022-12-08

Expression that reads slide(, fn, .before = 1) where the first argument is a stack of four colored blocks. This is followed by an arrow indicating that this computes fn() around: the first block, the first and second, second and third, and third and fourth.

Day 07: slider::slide()
2 min

Do window-based computations, like rolling averages and cumulative sums, by “sliding” across your data with slider::slide() and friends.

2022-12-07

glimpse() in bold letters in the foreground overlaying a background that faintly shows the output of glimpse for a data frame.

Day 06: glimpse()
2 min
An easy way to take a quick peek at all of the columns in your data frame (and as much data as fits on a row), glimpse() is like a transposed version of print() that…
2022-12-06

Three rows of color swatches (green, blue, and red) each of which shows a single square of a color on the left of an equation followed by = and c() surrounding four swatches of different shades of the color on the LHS of the equation.

Day 05: fct_collapse()
2 min

Easily combine multiple factor levels with forcats::fct_collapse().

2022-12-05

A cartoon showing two paths side-by-side. On the left is a scary spooky forest, with spiderwebs and gnarled trees, with file paths written on the branches like ~/mmm/nope.csv and setwd(/haha/good/luck/), with a scared looking cute fuzzy monster running out of it. On the right is a bright, colorful path with flowers, rainbow and sunshine, with signs saying here! and it&#039;s all right here! A monster facing away from us in a backpack and walking stick is looking toward the right path. Stylized text reads here: find your path.

Day 04: here::here()
2 min
Begin your journey to project-oriented-workflow enlightenment by using here::here() to build file paths.
2022-12-04

The number 1234567.89 shown three times, first using a comma for the grouping mark and a period for the decimal separator, second with a period for the grouping mark and a comma for the decimal separator, and last with a space for a grouping mark and a period for the decimal separator. The grouping marks are highlighted in blue and the decimal mark is highlighted in green.

Day 03: parse_number()
2 min
readr’s parsing functions can come in handy even after you’ve imported data. parse_number() is flexible enough to deal with things like leading characters, trailing white…
2022-12-03

Two progress bars, the first of which says Cleaning data #1 with a green bar and indicator of 100%, the second says Cleaning data #2 has a partially filled green progress bar and reads 28% followed by an ETA of 2s.

Day 02: cli_progress_*()
3 min

Show progress in your code using the cli_progress_*() family of functions from the cli package.

2022-12-02

A nested data frame (left), with a song character column, and a an artist list column is transformed into a data frame with one artist and song per row by using the unnest_longer() function. A data frame (right) with two character columns, song and artist, that contains multiple artists in the artist column as a string separated by commas is transformed into a tidy data frame with one song per row and one artist per row using separate_longer_delim().

Day 01: separate_longer_*()
3 min

Learn about tidyr’s separate_longer_*() functions which separate strings into multiple rows.

2022-12-01
No matching items