rOpenGov / geofi

R package for accessing Finnish geospatial data
https://ropengov.github.io/geofi/
Other
19 stars 6 forks source link

geofi::get_municipalities returns municipality codes and region codes without leading zeroes #38

Closed sampoves closed 3 years ago

sampoves commented 3 years ago

According to Statistics Finland, municipality codes always have three digits and leading zeroes are used where needed. The same is true for regions, except there only two digits are used.

geofi::get_municipalities outputs these codes without the leading zeroes. These are the column names: kunta, maakunta_code, and municipality_code.

As per Statistics Finland: https://www2.tilastokeskus.fi/fi/luokitukset/kunta/ https://www2.tilastokeskus.fi/fi/luokitukset/maakunta/

muuankarski commented 3 years ago

Hi, we could add a new variable municipality_code_char for municipalities and in similar vein for other *_code variants. Or we can add a new logical argument codes_as_character that would output the codes as three/two character long character vectors.

The current output (as integers) has been done on purpose as the attribute data these functions has been used with (Kela registers) uses integers for such codes.

Any ideas?

sampoves commented 3 years ago

Yes, I thought there must have been a purposeful decision behind this as the other get-prefixed functions in geofi do not have this issue. I would support implementing the logical argument codes_as_character.

muuankarski commented 3 years ago

First version can be installed and tested with

devtools::install_github("ropengov/geofi", ref = "feature/codes_as_character")

Implemented here: https://github.com/rOpenGov/geofi/commit/a92f72ddc77676ae51421e319c7fb8b013cbedac

Any input, comments or fixes, greatly appreciated!

pitkant commented 3 years ago

While elegant, the function affected also columns that needed no leading zeros - at least according to Tilastokeskus. For example, kielisuhde is just 0, 1, 2 or 3, not 00, 01, 02 or 03, according to https://www2.tilastokeskus.fi/fi/luokitukset/kielisuhde/

I put my proposed changes to PR #39

muuankarski commented 3 years ago

This is included in recent cran release https://cran.r-project.org/web/packages/geofi/index.html