How do write the following piece of code in R?
If you already have the names in R, you can iterate over the vector of names, and use the paste function. Here's the help page for it. sprintf would be another option, if you prefer that approach.

An example of this would be 

names &lt;- c("a", "b", "c")
querystring_a &lt;- "https://...../api/dataservice?sql = select * from db where name IN "
querystring_b &lt;- '\\'
querystring_c &lt;- "\'"
for(n in names){
    cat(paste(querystring_a, querystring_b, querystring_c, n, querystring_c, sep=""), sep="\n")
}


Return:

https://...../api/dataservice?sql = select * from db where name IN \'a'
https://...../api/dataservice?sql = select * from db where name IN \'b'
https://...../api/dataservice?sql = select * from db where name IN \'c'