Skip to content

Instantly share code, notes, and snippets.

@nischalshrestha
Created July 23, 2020 02:09
Show Gist options
  • Save nischalshrestha/ac6c467a875b297cb539e80164257499 to your computer and use it in GitHub Desktop.
Save nischalshrestha/ac6c467a875b297cb539e80164257499 to your computer and use it in GitHub Desktop.
R scrambled argument order
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