R dQuote() Function

The dQuote() function in R is used to add double quotes around a string.

This function is specifically helpful when you need to present strings in a formatted way, such as in printed output or in constructing messages and plots.

Syntax

dQuote(x)

Parameters

x: It is a string or character vector.

Return value

It returns a character vector with double quotes around each element.

Example 1: Basic usage

Simple program of dQuote() function

string <- "Expelli Armus"

dQuote(string)

Output

[1] "“Expelli Armus”"

Example 2: Pass integer as a string

Pass integer as a string

expression <- "1 + 2 / 2 * 4"

dQuote(expression)

Output

[1] "“1 + 2 / 2 * 4”"

For single quotes, use the sQuote() function, which works similarly.

Leave a Comment