R/str_wrap_RTL.R

Defines functions str_wrap_RTL

Documented in str_wrap_RTL

#' This is a wrapper for stringr::str_wrap and stringr::str_replace_all to wrap text and add an RTL unicode instruction (u202b) for every new line.
#'
#' @param width positive integer giving target line width in characters. A width less than or equal to 1 will put each word on its own line.
#' @param indent non-negative integer giving indentation of first line in each paragraph
#' @param exdent non-negative integer giving indentation of following lines in each paragraph
#'
#' @importFrom stringr str_wrap
#' @importFrom stringr str_replace_all
#' @importFrom magrittr %>%
#'
#' @export
str_wrap_RTL <- function(string, width = 80, indent = 0, exdent = 0){
  iconv(string, to = "UTF-8") %>%
    str_wrap(width, indent, exdent) %>%
    str_replace_all("\n", "\n\u202b") %>%
    paste0("\u202b", .)
}
sarid-ins/saridr documentation built on Nov. 10, 2020, 9:07 p.m.