Created
July 23, 2020 02:09
-
-
Save nischalshrestha/ac6c467a875b297cb539e80164257499 to your computer and use it in GitHub Desktop.
R scrambled argument order
This file contains hidden or 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
library(rlang) | |
fun <- function(x = 3, y, z = 1) { | |
paste(x, y, z) | |
} | |
# default arguments and regular argument order can be scrambled | |
# yet produce the same call | |
# look at actual call | |
rlang::call_standardise(quote(fun(1, 2, 3))) | |
# fun(x = 1, y = 2, z = 3) | |
fun(1, 2, 3) | |
# [1] "1 2 3" | |
# look at actual call | |
rlang::call_standardise(quote(fun(2, x=1, 3))) | |
# fun(x = 1, y = 2, z = 3) | |
fun(2, x=1, 3) | |
# [1] "1 2 3" | |
# look at actual call | |
rlang::call_standardise(quote(fun(z=3, x=1, 2))) | |
# fun(x = 1, y = 2, z = 3) | |
fun(z=3, x=1, 2) | |
# [1] "1 2 3" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment