引数

  • "..."と渡す引数
  • こちらに記事
  • こちらを"Dot-dot-dot"で検索すると記載
  • 全部の引数を"..."にしてもよい(関数名を変えるだけ)
myPlot <- function (...) {
  plot(...)
}

x <- y <- runif(10)
myPlot(x, y, pch=2, main="test")
  • "...","..."を二つ使えない
myPlot2 <- function (c(..., ...)) {
  plot(...)
}
> myPlot2 <- function (c(..., ...)) {
 エラー:   予想外の '(' です  ( "myPlot2 <- function (c(") 
>   plot(...)
 エラー:  '...' が不適切な文脈で使われました 
> }
 エラー:   予想外の '}' です  ( "}") 
> 
  • じゃあ、作成関数の中で、2つの"..."を使おうと思うと…
myPlot3 <- function (a=list(x,y,...),b=list(x,y,...)) {
	print(a)
	print(b)
}

x <- y <- runif(10)
x2 <- y2 <- rnorm(20)

myPlot3(list(x, y, pch=2, main="test"),list(x2,y2,pch=5,col=3))
  • これは、一応渡せる。
  • myPlot3()関数内で使うplot()関数にうまく渡せてない…