JosiahParry / youtube-tutorials

Code and slides used for youtube videos
https://josiahparry.github.io/youtube-tutorials/
12 stars 3 forks source link

rlang: functions for writing functions #5

Open JosiahParry opened 1 year ago

JosiahParry commented 1 year ago

example for diffusing code:

dplyr_but_later <- rlang::expr(library(dplyr)) 
rlang::eval_tidy(dplyr_but_later)

taking named arguments via dots, and collecting them into a list


make_new_list <- function(...) {
  my_list <- rlang::list2(...)
  my_list
}

splicing named list into argument !!!

splice_dfs <- function(...) {
  args <- rlang::list2(...)

  dplyr::bind_rows(!!!args)
}

# equivalent
splice_dfs <- function(...) {
  args <- rlang::list2(...)

  dplyr::bind_rows(rlang::splice(args))
}