在函数内部调用 sep=" "
Calling sep=" " inside the function
所以,我想在 do.call(paste) 中创建一个参数 sep = " " 。
fun <- function(x, sep=" "){
stopifnot(is.list(x))
k <- length(x)
n <- lengths(x)
stopifnot(length(unique(n))==1)
do.call(paste, c(x, sep))
}
不幸的是,这个没有用,我找不到任何类似的主题。
感谢您的帮助:)
我认为您可能需要 do.call
内的 sep = sep
,因为 lhs sep
用于 paste
,而 rhs sep
是输入参数函数 fun
,即
fun <- function(x, sep=" "){
stopifnot(is.list(x))
k <- length(x)
n <- lengths(x)
stopifnot(length(unique(n))==1)
do.call(paste, c(x, list(sep=sep)))
}
例子
> fun(as.list(seq(3)),"-")
[1] "1-2-3"
所以,我想在 do.call(paste) 中创建一个参数 sep = " " 。
fun <- function(x, sep=" "){
stopifnot(is.list(x))
k <- length(x)
n <- lengths(x)
stopifnot(length(unique(n))==1)
do.call(paste, c(x, sep))
}
不幸的是,这个没有用,我找不到任何类似的主题。 感谢您的帮助:)
我认为您可能需要 do.call
内的 sep = sep
,因为 lhs sep
用于 paste
,而 rhs sep
是输入参数函数 fun
,即
fun <- function(x, sep=" "){
stopifnot(is.list(x))
k <- length(x)
n <- lengths(x)
stopifnot(length(unique(n))==1)
do.call(paste, c(x, list(sep=sep)))
}
例子
> fun(as.list(seq(3)),"-")
[1] "1-2-3"