The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
This R package provides tools to work with swedish identity numbers such as personal identity numbers (personnummer) and organizational identity numbers (organisationsnummer).
Installation (Installation)
Example: personal identity numbers (Personal identity numbers)
Example: organizational identity numbers (Organizational identity number)
Licensing and Citations (Licensing and Citations)
References (References)
Install the stable release version in R:
Test the installation by loading the library:
We also recommend setting the UTF-8 encoding:
As a first step we need to convert personal identity numbers (pin) to the same standard format used by the Swedish tax authority.
example_pin <- c("640823-3234", "6408233234", "19640823-3230")
example_pin <- as.pin(example_pin)
example_pin
## [1] "196408233234" "196408233234" "196408233230"
## Personal identity number(s)
The next step is to test if the vector is a pin
object.
To do this we use the is.pin()
function.
## [1] TRUE
This only check the format of the pin. To check the pin using the
control number we use pin_ctrl()
.
## [1] TRUE TRUE FALSE
We can now use pin_birthplace()
and
pin_sex()
. To get information on sex and birthplace.
## [1] Male Male Male
## Levels: Male
## [1] Gotlands län Gotlands län Gotlands län
## 28 Levels: Stockholm stad Stockholms län Uppsala län ... Born after 31 december 1989
As the last step we can calculate the age based on the pin. We choose the date where we want to calculate the age. If date is not specified the current date is used.
## [1] 59 59 59
## [1] 35 35 35
It is also possible to format the pin for presentation in different
forms. (Note however that the output of format_pin
is just
a character and no longer a pin
object):
## [1] "1964-08-23-3234" "1964-08-23-3234" "1964-08-23-3230"
## [1] "(19) 64-08-23 - 3234" "(19) 64-08-23 - 3234" "(19) 64-08-23 - 3230"
Sometimes we want some example pin
s. We can easily
simulate pin
s using rpin()
:
## [1] "194712876764" "202010110787" "192610118990"
## Personal identity number(s)
Handling of organizational identity numbers is done in a similar fashion. But organizational numbers are only allowed to have one format.
example_oin <- c("556000-4615", "232100-0156", "802002-4280")
example_oin <- as.oin(example_oin)
example_oin
## [1] "556000-4615" "232100-0156" "802002-4280"
## Organizational identity number(s)
We can test if the vector has a correct format in a similar way as
for pin
.
## [1] TRUE
With a vector of oin
we can check if the organizational
number is correct.
## [1] TRUE TRUE TRUE
We can also check the type of organization.
## [1] Aktiebolag
## [2] Stat, landsting, kommuner, församlingar
## [3] Ideella föreningar och stiftelser
## 3 Levels: Aktiebolag ... Stat, landsting, kommuner, församlingar
Sometimes we want some example oin
s. We can easily
simulate oin
s using roin()
:
## [1] "358312-4031" "878143-3449" "939948-4279"
## Organizational identity number(s)
This work can be freely used, modified and distributed under the open license specified in the DESCRIPTION file.
Kindly cite the work as follows
## Kindly cite the sweidnumbr R package as follows:
##
## Magnusson, Mans and Bulow, Erik (2024). sweidnumbr: R tools to handle
## of swedish identity numbers. R package version 1.5.0 URL:
## https://github.com/rOpenGov/sweidnumbr
##
## A BibTeX entry for LaTeX users is
##
## @Misc{,
## title = {sweidnumbr: R tools to handle of swedish identity numbers.},
## author = {Mans Magnusson and Erik Bulow},
## url = {https://github.com/rOpenGov/sweidnumbr},
## year = {2024},
## note = {R package version 1.5.0},
## }
This vignette was created with
## R version 4.3.1 (2023-06-16)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Sonoma 14.2.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
##
## locale:
## [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Europe/Stockholm
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] sweidnumbr_1.5.0
##
## loaded via a namespace (and not attached):
## [1] backports_1.4.1 digest_0.6.33 R6_2.5.1 lubridate_1.9.2
## [5] fastmap_1.1.1 xfun_0.40 magrittr_2.0.3 glue_1.6.2
## [9] cachem_1.0.8 stringr_1.5.0 knitr_1.43 htmltools_0.5.6
## [13] timechange_0.2.0 generics_0.1.3 rmarkdown_2.24 lifecycle_1.0.4
## [17] cli_3.6.1 sass_0.4.7 jquerylib_0.1.4 compiler_4.3.1
## [21] rstudioapi_0.15.0 tools_4.3.1 checkmate_2.2.0 evaluate_0.21
## [25] bslib_0.5.1 yaml_2.3.7 rlang_1.1.2 jsonlite_1.8.7
## [29] stringi_1.7.12
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.