如何确定是否在R

时间:2018-11-20 17:28:04

标签: r recursion

标题说明了一切。

示例:

f <- function(x, r = TRUE) {

  out <- x + 10

  if(r) {
    out2 <- f(x, r = FALSE)
  }
  # Here I want something like:
  # if(f_was_called_recursively) {
  #   # only return out
  #   out
  # } else if(!f_was_called_recursively) { 
  #   # return the result from the recursive AND the 
  #   # non recursive calls if an recursive call has been made (if r = TRUE)
  #   if(r) {
  #   out <- list("outer" = out, "inner" = out2)
  #   } else {
  #   out <- list("outer" = out, "inner" = NA)
  #   }
  # }
  # out
}

问题: 我如何获得这个f_was_called_recursively

0 个答案:

没有答案