我对在某些函数中使用省略号(...
)感到困惑,即如何将包含参数的对象作为单个参数传递.
在Python中,它被称为"解包参数列表",例如.
>>> range(3, 6) # normal call with separate arguments
[3, 4, 5]
>>> args = [3, 6]
>>> range(*args) # call with arguments unpacked from a list
[3, 4, 5]
例如,在R中,函数file.path(...)
使用省略号.我希望有这样的行为:
> args <- c('baz', 'foob')
> file.path('/foo/bar/', args)
[1] 'foo/bar/baz/foob'
相反,我得到了
[1] 'foo/bar/baz' 'foo/bar/foob'
其中args
个元素没有"拆封"并同时进行判断.有相当于Python *arg
的R吗?