Skip to contents

retrieve_data retrieves a single data table.


  startyear = "",
  endyear = "",
  regionalmerkmal = "",
  regionalschluessel = "",
  sachmerkmal = "",
  sachschluessel = "",
  sachmerkmal2 = "",
  sachschluessel2 = "",
  sachmerkmal3 = "",
  sachschluessel3 = "",
  inhalte = "",
  genesis = NULL,
  language = "de",



name of the table to retrieve.


only retrieve values for years equal or larger to startyear. Default: "".


only retrieve values for years smaller or equal to endyear. Default: "".


key for Regionalklassifikation. See details for more information. Default: "".


only retrieve values for particular regional units. See details for more information. Default: "".

sachmerkmal, sachmerkmal2, sachmerkmal3

key for Sachklassifikation. Default: "".

sachschluessel, sachschluessel2, sachschluessel3

value for Sachklassifikation. Default: "".


retrieve only selected variables. Default is to retrieve all.


to authenticate a user and set the database (see below).


retrieve information in German "de" (default) or in English "en" if available.


other arguments send to the httr::GET request.


a data.frame. Value variables (_val) come with three additional variables (_qual, _lock, _err). The exact nature of these variables is unknown, but _qual appears to indicate if _val is a valid value. If _qual=="e" the value in _val is valid while if _qual!="e" (then _qual = ("-","/", ".", "x", ... ) ) it is typically zero should/might be set to NA.


Use retrieve_datalist to find the tablename based on the table series you are interested in. See the package description (wiesbaden) for details about setting the login and database.

The parameter regionalschluessel can either be a single value (a single Amtlicher Gemeindeschlüssel) or a comma-separated list of values supplied as string (no whitespaces). Wildcard character "*" is allowed. If regionalschluessel is set, the parameter regionalmerkmal must also be set to GEMEIN, KREISE, REGBEZ, or DLAND. The same logic applies to the parameter combination sachmerkmal and sachschluessel*. The parameter inhalte takes a 1-6 character long name of a variable in the table. If choosing multiple variables, delimit by ",", e.g. "STNW01,STNW02" (no whitespaces).

Limiting the data request to particular years (via the *year parameters), geographical units (via the regional* parameters) attributes (via the sach* parameters) or selected variables (via the inhalte parameter) is necessary if the API request fails to return any data. If you are not able to download the table because of size, inspect the metadata first (using retrieve_metadata or retrieve_valuelabel) and then limit the data request accordingly. See also examples below.


 if (FALSE) {
 # Retrieve values for the table 14111KJ002 which contains the 
 # federal election results on the county level. 
 # Assumes that user/password are stored via save_credentials()

 data <- retrieve_data(tablename="14111KJ002", genesis=c(db="regio") )

 # ... only the values for the AfD. 

 data <- retrieve_data(tablename="14111KJ002", sachmerkmal="PART04", 
   sachschluessel="AFD", genesis=c(db="regio") )

# ... or only values from Saxony

 data <- retrieve_data(tablename="14111KJ002", regionalmerkmal="KREISE", 
   regionalschluessel="14*", genesis=c(db="regio") )

# Limiting the number of data points is in particular important for 
# large tables. For example, this data request fails: 

data <- retrieve_data(tablename="33111GJ005", genesis=c(db='regio'))

# But after limiting the request to one year, the data is returned:

data <- retrieve_data(tablename="33111GJ005", genesis=c(db='regio'), startyear=2019, endyear=2019)

# An alternative strategy is to only request a subset of the variables. 
# For example, this data request fails: 

data <- retrieve_data("12711GJ002", genesis=c(db="regio"))

# But when requesting only one instead of all variables, the data is returned: 

data <- retrieve_data("12711GJ002", inhalte="BEV081", genesis=c(db="regio"))