Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paste quotation marks into character string, within a loop

Tags:

r

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?

like image 792
guyabel Avatar asked Dec 15 '10 17:12

guyabel


People also ask

How do you put quotes in a string in R?

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.

How do you pass a double quote in a string?

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);


1 Answers

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="") 
like image 122
NPE Avatar answered Sep 17 '22 18:09

NPE