2

My aim is to query wikidata using R. I just realized that Wikidata Query Service offers code examples in order to so:

  1. Go to https://w.wiki/AkK
  2. Execute query
  3. Click on </> Code next to the Download button
  4. Select R. This gives the following result:
#http://www.r-bloggers.com/sparql-with-r-in-less-than-5-minutes/

library(SPARQL) # SPARQL querying package
library(ggplot2)

endpoint <- "https://query.wikidata.org/sparql"
query <- 'SELECT  (COUNT(?item) AS ?count) \n{\n  ?item wdt:P31 wd:Q146.\n  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }\n} '

qd <- SPARQL(endpoint,query)
df <- qd$results

When I run this code the following error message appears: "Opening and ending tag mismatch". The problem seems to be platform independent. What do I need to do in order to avoid getting this error message?

logi-kal
  • 7,107
  • 6
  • 31
  • 43
kalakaru
  • 131
  • 3

1 Answers1

0

The correct code is

qd <- SPARQL(endpoint,query,curl_args=list(useragent=R.version.string))

userJT
  • 11,486
  • 20
  • 77
  • 88