tldr: Don't worry about them, they're not really there. It's just something added by print
Those \
are escape characters that tell R to ignore the special properties of the characters that follow them. Look at the output of your paste function:
paste('//*[@id="',tag,'"]', sep = "")
[1] "//*[@id=\"coll276\"]"
You'll see that the output, since it is a string, is enclosed in double quotes ""
. Normally, the double quotes inside your string would break the string up into two strings with bare code in the middle:
"//*[@id\" coll276 "]"
To prevent this, R "escapes" the quotes in your string so they don't do this. This is just a visual effect. If you write your string to a file, you'll see that those escaping \
aren't actually there:
write(paste('//*[@id="',tag,'"]', sep = ""), 'out.txt')
This is what is in the file:
//*[@id="coll276"]
You can use cat
to print the exact value of the string to the console (Thanks @LukeC):
cat(paste('//*[@id="',tag,'"]', sep = ""))
//*[@id="coll276"]
Or use single quotes (if possible):
paste('//*[@id=\'',tag,'\']', sep = "")
[1] "//*[@id='coll276']"