R/op-concat.R

Defines functions `%+%`

#' Concatenate strings
#'
#' Concatenate two strings (scalar character values) together, and
#' automatically separate them by a single space.
#'
#' @name op-concat
#'
#' @param x,y `[character(1)]`
#'
#'   Strings to be concatenated.
#'
#' @returns A `character(1)` composed of `x` and `y` separated by a space.
#'
#' @examples
#' identical("My name is" %+% "Foo Baz.", "My name is Foo Baz.") # TRUE
#'
#' @export
`%+%` <- function(x, y)
{
    if (!is_scalar_chr(x) || !is_scalar_chr(y)) {
        ui_stop(
            "both {.arg x} and {.arg y} must be {.code character(1)}.",
            ui_todo("Be explicit, and first convert these arguments with {.fun base::as.character}."))
    }

    return(sprintf("%s %s", x, y))
}
jeanmathieupotvin/dotprofile documentation built on Dec. 20, 2021, 10:08 p.m.