R/escaped_quote.R

Defines functions escapedQuote

Documented in escapedQuote

#' Escape quotes for shell commands
#'
#' This helper prepares character vectors for use in shell commands by
#' quoting them with \code{shQuote()} and (double) escaping any internal
#' double quotes.
#'
#' @param x A character vector that may contain double quotes.
#' @param double Boolean. Should the quotes be escaped twice? Default: FALSE
#'
#' @return A character vector with all double quotes double escaped so
#'   that it can safely be passed to a command line call.
#'
#' @examples
#' \dontrun{
#' escapedQuote('foo "bar" baz')
#' }
#'
#' @keywords internal
escapedQuote <- function(x, double=FALSE) {
  if (double)
    gsub('"', '\\\\"', shQuote(x, type = "cmd"))
  else
    gsub('"', '\\"', shQuote(x, type = "cmd"))
}

Try the reproducibleRchunks package in your browser

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

reproducibleRchunks documentation built on Aug. 8, 2025, 6:38 p.m.