There are three common ways to remove quotes from strings in R:
Method 1: Use print()
print(some_strings, quote=FALSE)
Method 2: Use noquote()
noquote(some_strings)
Method 3: Use cat()
cat(some_strings)
The following examples show how to use each method with the following vector of strings:
#define vector of strings
some_strings <- c("hey", "these", "are", "some", "strings")
#view vector
some_strings
[1] "hey" "these" "are" "some" "strings"
Notice that the strings are printed with quotes by default.
Example 1: Remove Quotes from Strings Using print()
The following code shows how to use the print() function to print the strings with the quotes removed:
#print vector of strings without quotes print(some_strings, quote=FALSE) [1] hey these are some strings
Example 2: Remove Quotes from Strings Using noquote()
The following code shows how to use the noquote() function to print the strings with the quotes removed:
#print vector of strings without quotes noquote(some_strings) [1] hey these are some strings
Example 3: Remove Quotes from Strings Using cat()
The following code shows how to use the cat() function to print the strings with the quotes removed:
#print vector of strings without quotes cat(some_strings) hey these are some strings
You can also use the \n argument to print each string without quotes on a new line:
#print vector of strings without quotes each on a new line cat(paste(some_strings, "\n")) hey these are some strings
Notice that each string in the vector is printed on a new line.
Additional Resources
The following tutorials explain how to perform other common tasks in R:
How to Remove Characters from String in R
How to Find Location of Character in a String in R
How to Remove Spaces from Strings in R