1

I am trying to read from an API where the URL contains a non-standard latin character in R, but am getting an error. Similar URLs without a funny character work fine.

I get following error

> RJSONIO::fromJSON("https://api-prod.footballindex.co.uk/exchange-orders/market-depth/kylian-mbappé")
Error in file(con, "r") : cannot open the connection

Standard characters work fine

res <- RJSONIO::fromJSON("https://api-prod.footballindex.co.uk/exchange-orders/market-depth/neymar")
Thomas L.
  • 524
  • 1
  • 5
  • 17
bc17568
  • 13
  • 2

1 Answers1

3

This is more of an url-encoding problem than an R or JSON one. But this should work:

RJSONIO::fromJSON("https://api-prod.footballindex.co.uk/exchange-orders/market-depth/kylian-mbapp%C3%A9")

This link could also help you for theoretical background information and this one for practical conversions.

You can also use utils::URLencode to do the conversion within R:

utils::URLencode("https://api-prod.footballindex.co.uk/exchange-orders/market-depth/kylian-mbappé")
[1] "https://api-prod.footballindex.co.uk/exchange-orders/market-depth/kylian-mbapp%C3%A9"
Thomas L.
  • 524
  • 1
  • 5
  • 17
  • Thanks so much, however any idea why I get this? ```> URLencode('é') [1] "%E9"``` rather than %C3%A9 like you do? Presumably a setting – bc17568 Nov 20 '20 at 21:06
  • It depends on the character-set: hhttps://www.w3schools.com/tags/ref_urlencode.asp Windows-1252 <> UTF-8 – Thomas L. Nov 21 '20 at 04:04