2
的時候,這裏是什麼,我希望發生的如何添加默認元素`...`傳遞這些參數到另一個功能
myfun <-
function(...){
# myfun only passes `...` on to the plot function
plot(
... ,
if(!'xlab' %in% names(list(...))) xlab = 'mylabel' ,
if(!'ylab' %in% names(list(...))) ylab = 'ylabel'
)
}
# works the way i want: user specified `xlab` and `ylab` so `...` used them
myfun(1 , 1 , xlab = "new label" , ylab = "another label")
# fails
myfun(1 , 1)
# Error in plot.window(...) : invalid 'xlim' value
,因爲用戶沒有指定xlab
和ylab
最小的可重複的例子,我想讓我的函數使用我設置的默認值。所以
plot(1 , 1 , xlab = 'mylabel' , ylab = 'ylabel')
什麼這樣做,如果我有很多可能性,例如xlab
和ylab
最聰明的方法是什麼?我可能需要爲title=
和xlim=
和ylim=
添加默認值,因此寫出每個組合都不可行?謝謝!!
正是我一直在尋找for..thank你! https://github.com/DjalmaPessoa/convey/commit/4dd0d2d2f36385423e9c03fc6cb2ed51e060fcf9 –
嘿,謝謝你的引用! – Alex