Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active October 7, 2017 05:51
Show Gist options
  • Save yutannihilation/e7dc590fb9fafa0819152a65045a6303 to your computer and use it in GitHub Desktop.
Save yutannihilation/e7dc590fb9fafa0819152a65045a6303 to your computer and use it in GitHub Desktop.
f <- function(return_true = TRUE) {
function(return_true = return_true) {
if (return_true) return(TRUE)
FALSE
}
}
f()
#> function(return_true = return_true) {
#> if (return_true) return(TRUE)
#> FALSE
#> }
#> <environment: 0x0000000017f285c8>
f()()
#> Error in f()(): promise already under evaluation: recursive default argument reference or earlier problems?
@yutannihilation
Copy link
Author

ありがとうございます。すみません、コメントに気付いていませんでした。。
ちょっとまだ理解しきれていないのですが、循環参照なのでこういうエラーになるんですね。なるほどー。

変数名が別なら大丈夫なんですね。

f <- function(return_true_default = TRUE) {
  function(return_true = return_true_default) {
    if (return_true) return(TRUE)
    FALSE
  }
}
f()()
#> [1] TRUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment