sweidnumbr : Structural handling of swedish identity numbers

This R package provides tools to work with swedish identity numbers such as personal identity numbers (personnummer) and organizational identity numbers (organisationsnummer).

Table of contents

Installation (Installation)

Example: personal identity numbers (Personal identity numbers)

Example: organizational identity numbers (Organizational identity number)

Licensing and Citations (Licensing and Citations)

References (References)

Installation

Install the stable release version in R:

install.packages("sweidnumbr")

Test the installation by loading the library:

library(sweidnumbr)

We also recommend setting the UTF-8 encoding:

Sys.setlocale(locale="UTF-8") 

Example: personal identity numbers

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

The next step is to test if the vector is a pin object. To do this we use the is.pin() function.

is.pin(example_pin)

This only check the format of the pin. To check the pin using the control number we use pin_ctrl().

pin_ctrl(example_pin)

We can now use pin_birthplace() and pin_sex(). To get information on sex and birthplace.

pin_sex(example_pin)
pin_birthplace(example_pin)

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.

pin_age(example_pin)
pin_age(example_pin, date = "2000-01-01")

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):

format_pin(example_pin, "%Y-%m-%d-%N")
format_pin(example_pin, "%P")

Sometimes we want some example pins. We can easily simulate pins using rpin():

rpin(3)

Example: organizational identity numbers

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

We can test if the vector has a correct format in a similar way as for pin.

is.oin(example_oin)

With a vector of oin we can check if the organizational number is correct.

oin_ctrl(example_oin)

We can also check the type of organization.

oin_group(example_oin)

Sometimes we want some example oins. We can easily simulate oins using roin():

roin(3)

Licensing and Citations

This work can be freely used, modified and distributed under the open license specified in the DESCRIPTION file.

Kindly cite the work as follows

citation("sweidnumbr")

References

Session info

This vignette was created with

sessionInfo()


Try the sweidnumbr package in your browser

Any scripts or data that you put into this service are public.

sweidnumbr documentation built on March 31, 2020, 5:24 p.m.