| shEncode | R Documentation |
Quote a string to be passed to an operating system shell.
shEncode(string, type = NULL, unix.type = NULL, windows.type = "Rscript")
commandEncode(string, type = NULL, unix.type = NULL, windows.type = "Rscript")
commandQuote(string, type = NULL, unix.type = NULL, windows.type = "Rscript")
string |
a character vector, usually of length one. |
type |
character string: the type of quoting. Partial matching is supported. |
unix.type |
character string: the type of quoting under Unix-alikes when
|
windows.type |
character string: the type of quoting in Windows when
|
The choices for quoting are "sh", "perl", "python",
"R", "R CMD", "Rcmd", "Rgui", "Rscript",
and "Rterm". The default for quoting under Unix-alikes is "sh",
while in Windows it is "Rscript".
From my testing with shQuote, it seems like it fails in a
few edge cases that shEncode can handle correctly.
Those few cases that shQuote handles incorrectly are:
under Unix-alikeswith type = "csh" and string
contains a dollar sign or grave accent and string has a trailing
single quote, string loses its trailing single quote.
in Windowswith type = "cmd" and string contains a
double quote preceded by at least one backslash, the preceding
backslashes aren't escaped. Also, when string contains a set of
trailing backslashes, they aren't escaped.
character vector, the same length as string, with the attributes of
string (after possible coercion to character), excluding class.
Rscript, python
fun <- function(string) {
cat(c(
"string ", string , "\n",
"sh ", essentials::shEncode(string, type = "sh" ), "\n",
"Rscript ", essentials::shEncode(string, type = "Rscript"), "\n",
"R ", essentials::shEncode(string, type = "R" ), "\n"
), sep = "")
}
fun("abc$def`gh`i\\j")
fun("testing \\\"this\\\"")
fun("\"testing\" $this$ 'out'")
## Not run:
essentials:::.system(paste(c(
"perl",
"-e",
essentials::shEncode(r"{print "test \"this\" out\n";}",
windows.type = "perl")
), collapse = " "))
## End(Not run)
## Not run:
essentials:::.system(paste(c(
"python",
"-c",
essentials::shEncode(r"{print("test \"this\" out")}",
windows.type = "python")
), collapse = " "))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.