R: Using ellipsis with a function that takes a arbitrary number of arguments -
many times, find myself typing following
print(paste0(val1,',',val2,',',val3)) print output function variables separated comma. it handy when want copy generate csv file output.
i wondering if can write function in r me. many attempts, following.
ppc <- function(string1,string2,...) print(paste0(string1,',',string2,',',...,)) it works @ maximum of 3 arguments.
> ppc(1,2,3) [1] "1,2,3" > ppc(1,2,3,4) [1] "1,2,34" ppc(1,2,3,4) should have given "1,2,3,4". how can correct function? somehow believe possible in r.
you don't need write own function. can paste.
paste(1:3,collapse=",") # [1] "1,2,3"
Comments
Post a Comment