R中函数的参数的所有有效值

Ant*_*nko 17 arguments r function

假设我们有一个R函数,其参数必须从有限的元素集中选择.喜欢qplot(..., geom="").并且geom只能采用某些值,例如barpoint.

如何找出给定函数的参数可能带来的所有有效值?除了文档或互联网,它们往往会错过所有可能的价值观.也许,一些R功能可以帮助吗?

小智 6

如果感兴趣的函数定义为

f <- function(a = c("foo","bar")) {
    match.arg(a)
}
Run Code Online (Sandbox Code Playgroud)

ie when the options are defined as a vector to be later checked with match.argfunction, then you could use the formalsfunction which would give you a list of arguments with the values like in the following example

> formals(f)
$a
c("foo", "bar")
Run Code Online (Sandbox Code Playgroud)

否则我认为没有 RTFSing 就不可能获得所有有效的参数值。