最佳答案
我有一个函数 f,它接受两个参数(p1和 p2) :
如果对于参数 p2没有向函数传递值,则应改为使用 p1 ^ 2的值。但是我怎么才能在函数中找出,是否给出了一个值。问题是,如果没有值,变量 p2就不会初始化。因此,我不能测试 p2是 NULL。
f <- function(p1, p2) {
if(is.null(p2)) {
p2=p1^2
}
p1-p2
}
Is it somehow possible to check if a value for p2 was passed to the function or not? (I could not find an isset() - function or similar things.)