Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的问题很简单。
x=list(type="call") FUN <- function(x=list(type=c("call","put"))) { x$type=match.arg(x$type) }
这将返回一个错误:
> FUN(x) Error in match.arg(x$type) : 'arg' should be one of “”
有任何想法吗?
也许这就是你想要的:
FUN <- function(x=list(type=c("call","put"))) { x$type=match.arg(x$type, c('call', 'put')) } > print(FUN()) [1] "call" > print(FUN(x)) [1] "call" > print(FUN(list(type="put"))) [1] "put"