Using R, I want to produce multiple character strings such as:
"modelCheck("var1_d.bug")" "modelCheck("var2_d.bug")" ... "modelCheck("var10_d.bug")"
I would usually use a for loop and paste (if I did not have to worry about the double quotation marks) as such:
for(i in 1:10){ str<-paste("modelCheck(var",i,"_d.bug)",sep="") print(str) }
However, I need to include the double quotation marks within the character string, hence the appeal for help?
To add single quotes to strings in an R data frame column, we can use paste0 function. This will cover the strings with single quotes from both the sides but we can add them at the initial or only at the last position.
Double Quotes inside verbatim strings can be escaped by using 2 sequential double quotes "" to represent one double quote " in the resulting string. var str = @"""I don't think so,"" he said. "; Console. WriteLine(str);
Simply escape the quotation marks with backslashes:
paste("modelCheck(var\"",i,"_d.bug\")",sep="")
An alternative is to use single quotes to enclose the string:
paste('modelCheck(var"',i,'_d.bug")',sep="")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With