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 '
:
'
End first quotation which uses single quotes."
Start second quotation, using double-quotes.'
Quoted character."
End second quotation, using double-quotes.'
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
Aggregating Unique Values in Columns to Single Dataframe "Cell"
What Is Your Preferred Style for Naming Variables in R
How to Print Double Quotes (") in R
Predict X Values from Simple Fitting and Annoting It in the Plot
Month Language in the As.Date Function
Does White Space Slow Down Processing
How to Apply Dplyr's Select(,Starts_With()) on Rows, Not Columns
Can Not Connect Postgresql(Over Ssl) with Rpostgresql on Windows
Fit Many Formulae at Once, Faster Options Than Lapply
Override Horizontal Positioning with Ggrepel
R Shiny Ggplot Bar and Line Charts with Dynamic Variable Selection and Y Axis to Be Percentages
Get Data Frame from Character Variable
Datatype for Linear Model in R
Plotting Wide Format Data Using R Ggplot
Graph Flow Chart of Transition from States
Display Duplicate Records in Data.Frame and Omit Single Ones