Home > Enterprise >  How to paste values from multiple inputs through ellipsis?
How to paste values from multiple inputs through ellipsis?

Time:06-09

I'm trying to get all the variables entered through the ... to be stringed together with a plus in the middle.

rhs <- function(...) {
  paste(..., "   ")
}
rhs("a", "c")

For example, the above function should return

"a   c"

but right now it is returning this:

"a c    "

CodePudding user response:

Try this

rhs <- function(...) {
     lst <- list(...)
     paste0(lst[[1]], "   " , lst[[2]])
 }

rhs("a", "c")


CodePudding user response:

I liked Akrun's answer before it was deleted because it also accepted a single variable.

rhs <- function(...) {
    do.call(paste, c(list(...), sep = "   "))
 
}
  •  Tags:  
  • r
  • Related