Created
March 12, 2019 16:28
-
-
Save tylerlittlefield/ec59f2c12d3f49e33acf160f0c08f730 to your computer and use it in GitHub Desktop.
Avoid arg = NULL in R functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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