R/join.R

Defines functions strs_join

Documented in strs_join

#' Join elements into a single string with a separator
#'
#' `strs_join` concatenates elements of `iterable` using `sep`. It is similar to
#' Python's `str.join()`.
#'
#' @param sep A string separator used to join the elements.
#' @param iterable A character vector to be joined.
#' @return A single string with elements of `iterable` joined by `sep`.
#' @examples
#' strs_join("-", c("hello", "world"))
#' strs_join("", c("hello", "world"))  # no separator
#' @seealso [Python str.join() documentation](https://docs.python.org/3/library/stdtypes.html#str.join)
#' @export
strs_join <- function(sep, iterable) {
  stringi::stri_flatten(iterable, collapse = sep)
}

Try the strs package in your browser

Any scripts or data that you put into this service are public.

strs documentation built on Sept. 11, 2024, 6:44 p.m.