All valid values of an argument of a function in R

后端 未结 1 430
孤街浪徒
孤街浪徒 2021-02-07 04:40

Suppose we have an R function whose arguments must be selected out of a finite set of elements. Like qplot(..., geom=\"\"). And geom can take only some

1条回答
  •  再見小時候
    2021-02-07 05:17

    If the function of interest is defined like

    f <- function(a = c("foo","bar")) {
        match.arg(a)
    }
    

    i.e. when the options are defined as a vector to be later checked with match.arg function, then you could use the formals function which would give you a list of arguments with the values like in the following example

    > formals(f)
    $a
    c("foo", "bar")
    

    Otherwise I don't think it is possible to get all valid argument values without RTFSing.

    0 讨论(0)
提交回复
热议问题