R/enc-utils.R

Defines functions strsplit_ gsub_ sub_

# keep encoding, even if useBytes = TRUE

sub_ <- function(pattern, replacement, x, ...) {
  enc <- Encoding(x)
  ret <- sub(pattern, replacement, x, ...)
  if (length(ret)) Encoding(ret) <- enc
  ret
}

gsub_ <- function(pattern, replacement, x, ...) {
  enc <- Encoding(x)
  ret <- gsub(pattern, replacement, x, ...)
  if (length(ret)) Encoding(ret) <- enc
  ret
}

strsplit_ <- function(x, ...) {
  enc <- Encoding(x)
  ret <- strsplit(x, ...)
  for (i in seq_along(ret)) {
    Encoding(ret[[i]]) <- enc[i]
  }
  ret
}

Try the cli package in your browser

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

cli documentation built on March 31, 2023, 9:04 p.m.