3

重複の可能性:
substituteを使用して引数名を取得します

これは、ベクトル自体list(...)またはその形式の何かを取得することとは-異なる-ことに注意してください。私ができるようにしたいのは...、解析が行われる前に、渡されたすべての引数を単に「エコー」することです。

例:次のように動作する関数が必要です。

f(apple, banana, car)
## --> returns c("apple", "banana", "car"), 
## ie, skips looking for the objects apple, banana, car

私が得た最も近いものは

f <- function(...) {
  return( deparse( substitute( ... ) ) )
}

ただし、これは。によってキャッチされた最初の引数'のみを返します...。考え?

4

1 に答える 1

6
f <- 
  function(...){
     match.call(expand.dots = FALSE)$`...`  
  }

?match.callからの説明:

 1. match.call returns a call in which all of the specified arguments are specified by their full names .
 2. Here it is used to pass most of the call to another function, often model.frame. 
    Here the common idiom is that expand.dots = FALSE

ここにいくつかのテストがあります:

f(2)        # call of a static argument  
[[1]]
[1] 2

> f(x=2)  # call of setted argument
$x
[1] 2

> f(x=y)  # call of symbolic argument
$x
y
于 2012-12-07T19:37:04.043 に答える