Selena Gomez Selena Gomez - 11 months ago 56
R Question

How to escape the symbol of percentage '%' in r?

In an url, I am dealing with the special character '%' that I should pass as a string. The url contain some argumnents so I use

How to escape the symbol '%' in r ?

start <- 1
#%s is my variable
url<-(sprintf('', start, start))

invalid format '%2Cn%3A'; use format %s for character objects

Answer Source

As the helpfile for sprintf states:

A wrapper for the C function sprintf, ...

Thus, you escape it in R the same way you do for C, using double precentage signs %% to produce one %, as per

How to escape sprintf() % marks so they wont be recognized as variables?

On your code, we produce a url presumably extracting the first page in this search:

url<-(sprintf('‌​A172282%%2Cn%%3A%%21‌​493964%%2Cn%%3A50239‌​4%%2Cn%%3A281052%%2C‌​n%%3A12556502011%%2C‌​n%%3A3017941&page=%s‌​&ie=UTF8', start, start))


> url
[1] ""