在参数默认值中使用If语句

我想知道在参数的默认值中包含if语句是否合法。

例如:

foo <- function(x, description=if(x>0) "pos" else "non-pos") {
  cat(x, description, "\n")
}

该函数成功运行,并且执行您期望的操作:

> foo(1)
1 pos
> foo(-1)
-1 non-pos 

But, when debugging it interactively, I get a 'promise already under evaluation' error when trying to access the description argument multiple times:

> debug(foo)
> foo(1)
debugging in: foo(1)
debug at #1: {
    cat(x, description, "\n")
}
Browse[2]> description
debug at #1: [1] "pos"
Browse[3]> description
Error: promise already under evaluation: recursive default argument reference or earlier problems?

谢谢