Skip to content

Instantly share code, notes, and snippets.

@tylerlittlefield
Created March 12, 2019 16:28
Show Gist options
  • Save tylerlittlefield/ec59f2c12d3f49e33acf160f0c08f730 to your computer and use it in GitHub Desktop.
Save tylerlittlefield/ec59f2c12d3f49e33acf160f0c08f730 to your computer and use it in GitHub Desktop.
Avoid arg = NULL in R functions
handle_null <- function(.data) {
switch(
as.character(missing(.data)),
"TRUE" = NULL,
"FALSE" = .data
)
}
# so we can have docs like this
rx_anything(.data, mode = "greedy")
# instead of
rx_anything(.data = NULL, mode = "greedy")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment