Finnish open government data toolkit for R

This R package provides miscellaneous tools for Finnish open government data. Your contributions, bug reports and other feedback are welcome!

Available data sources and tools

Installation (Asennus)

Finnish provinces (Maakuntatason informaatio)

Finnish municipalities (Kuntatason informaatio)

ID conversion tools

Finnish personal identification number (HETU) (Henkilotunnuksen kasittely)

Visualization tools (Visualisointirutiineja)

See also other rOpenGov packages, in particular:

  • gisfin Visualization of Finnish geographic information
  • helsinki Helsinki open data tools
  • sotkanet THL Sotkanet database on health and demography
  • pxweb PX-Web interface to access data fom Statistics Finland and other PX-Web compliant sources
  • finpar Finnish parliament data


We assume you have installed R. If you use RStudio, change the default encoding to UTF-8. Linux users should also install CURL.

Install the stable release version in R:


Test the installation by loading the library:


Development version for developers:


We also recommend setting the UTF-8 encoding:


Brief examples of the package tools are provided below. Further examples are available in Louhos-blog and in our Rmarkdown blog.

Province information (Maakunnat)

Finnish-English translations

Finnish-English translations for province names (we have not been able to solve all encoding problems yet; solutions welcome!):

translations <- load_sorvi_data("translations")

Municipality information

Finnish municipality information is available through Statistics Finland (Tilastokeskus; see stafi package) and Land Survey Finland (Maanmittauslaitos). The row names for each data set are harmonized and can be used to match data sets from different sources, as different data sets may carry different versions of certain municipality names.

Land Survey Finland (municipality information)

Source: Maanmittauslaitos, MML. <- get_municipality_info_mml()


Municipality-Province mapping

Map all municipalities to correponding provinces

m2p <- municipality_to_province() 
kable(head(m2p)) # Just show the first ones

Map selected municipalities to correponding provinces:

municipality_to_province(c("Helsinki", "Tampere", "Turku")) 

Speed up conversion with predefined info table:

m2p <- municipality_to_province(c("Helsinki", "Tampere", "Turku"),

Municipality name-ID conversion

Municipality name to code

convert_municipality_codes(municipalities = c("Turku", "Tampere"))

Municipality codes to names

convert_municipality_codes(ids = c(853, 837))

Complete conversion table

municipality_ids <- convert_municipality_codes()
kable(head(municipality_ids)) # just show the first entries

Synonyme conversions

Generic conversion of synonymes into harmonized terms.

First, get a synonyme-name mapping table. In this example we harmonize Finnish municipality names that have multiple versions. But the synonyme list can be arbitrary.

f <- system.file("extdata/municipality_synonymes.csv", package = "sorvi")
synonymes <- read.csv(f, sep = "\t")         

Validate the synonyme list and add lowercase versions of the terms:

synonymes <- check_synonymes(synonymes, include.lowercase = TRUE)

Convert the given terms from synonymes to the harmonized names:

harmonized <- harmonize_names(c("Mantta", "Koski.Tl"), synonymes)

Personal identification number (HETU)

Extracting information from a Finnish personal identification number

##          hetu gender personal.number checksum       date day month year
## 1 111111-111C   Male             111        C 1911-11-11  11    11 1911
##   century.char
## 1            -

The function accepts also vectors as input, returning a data frame:

kable(hetu(c("010101-0101", "111111-111C")))
hetu gender personal.number checksum date day month year century.char
010101-0101 Female 10 1 1901-01-01 1 1 1901 -
111111-111C Male 111 C 1911-11-11 11 11 1911 -

Extracting specific field

hetu(c("010101-0101", "111111-111C"), extract = "gender")
## [1] "Female" "Male"

Validate Finnish personal identification number:

valid_hetu("010101-0101") # TRUE/FALSE
## [1] TRUE

Visualization tools

Draw regression curve with smoothed error bars based on the Visually-Weighted Regression by Solomon M. Hsiang. The sorvi implementation extends Felix Schonbrodt’s original code.

p <- regression_plot(Sepal.Length ~ Sepal.Width, iris)