How to Print Double Quotes (") in R

How to print double quotes () in R

Use cat:

cat("\" \"xml\" \"")

OR

cat('" "','xml','" "')

Output:

" "xml" "

Alternative using noqoute:

 noquote(" \" \"xml\" \" ")

Output :

 " "xml" " 

Another option using dQoute:

dQuote(" xml ")

Output :

"“ xml ”"

Are double and single '' quotes (always) interchangeable in R?

> print(""hi"")
Error: unexpected symbol in "print(""hi"
> print("'hi'")
[1] "'hi'"
> print("hi")
[1] "hi"

How to print variables inside quotes in message()

You have two three options of doing this

Option 1: Escape the quotes. To do this, you have to use \".

cat("You entered ", "\"", min.v, " ", max.v,"\"", sep="")
You entered "5 10"

Option 2: Embed your double quotes in single quotes:

cat("You entered ", '"', min.v, " ", max.v,'"', sep="")
You entered "5 10"

Edit: with acknowledgement to @baptiste, in an effort to make this answer comprehensive

Option3: Use the function dQuote():

options(useFancyQuotes=FALSE)
cat("You entered ", dQuote(paste(min.v, max.v)), sep="")
You entered "5 10"

Remove quotes from a character vector in R

as.name(char[1]) will work, although I'm not sure why you'd ever really want to do this -- the quotes won't get carried over in a paste for example:

> paste("I am counting to", char[1], char[2], char[3])
[1] "I am counting to one two three"

How to escape single quotes within single quoted strings

If you really want to use single quotes in the outermost layer, remember that you can glue both kinds of quotation. Example:

 alias rxvt='urxvt -fg '"'"'#111111'"'"' -bg '"'"'#111111'"'"
# ^^^^^ ^^^^^ ^^^^^ ^^^^
# 12345 12345 12345 1234

Explanation of how '"'"' is interpreted as just ':

  1. ' End first quotation which uses single quotes.
  2. " Start second quotation, using double-quotes.
  3. ' Quoted character.
  4. " End second quotation, using double-quotes.
  5. ' Start third quotation, using single quotes.

If you do not place any whitespaces between (1) and (2), or between (4) and (5), the shell will interpret that string as a one long word.

When should I use double or single quotes in JavaScript?

The most likely reason for use of single vs. double in different libraries is programmer preference and/or API consistency. Other than being consistent, use whichever best suits the string.

Using the other type of quote as a literal:

alert('Say "Hello"');
alert("Say 'Hello'");

This can get complicated:

alert("It's \"game\" time.");
alert('It\'s "game" time.');

Another option, new in ECMAScript 6, is template literals which use the backtick character:

alert(`Use "double" and 'single' quotes in the same string`);
alert(`Escape the \` back-tick character and the \${ dollar-brace sequence in a string`);

Template literals offer a clean syntax for: variable interpolation, multi-line strings, and more.

Note that JSON is formally specified to use double quotes, which may be worth considering depending on system requirements.



Related Topics



Leave a reply



Submit