1#' Join the elements of a character vector or list into a string. 2#' 3#' Return a string which is the concatenation of the elements in the iterable \code{iterable}, 4#' where \code{sep} is the separator between elements. 5#' 6#' @param iterable A character vector. 7#' @param sep A character string. 8#' 9#' @return A character vector or list. 10#' 11#' @references \url{https://docs.python.org/3/library/stdtypes.html#str.join} 12#' 13#' @seealso \code{\link{pystr_split}} 14#' 15#' @examples 16#' pystr_join(c("A", "B", "C")) 17#' pystr_join(c(1, 2, 3), "+") 18#' pystr_join(list(c(1, 2, 3), c(4, 5, 6)), ", ") 19#' 20#' @export 21pystr_join <- function(iterable, sep="") { 22 if (is.list(iterable)) { 23 if (length(iterable) > 0) { 24 vals = list() 25 26 for (i in 1:length(iterable)) { 27 vals[[i]] = paste(iterable[[i]], collapse=sep) 28 } 29 30 return(vals) 31 } 32 return(list()) 33 } 34 return(paste(iterable, collapse=sep)) 35} 36