Skip to content

Commit 04671b8

Browse files
committed
Rjournal changes to main
1 parent ee2b85c commit 04671b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+348
-6200
lines changed

.Rbuildignore

100755100644
File mode changed.

.gitignore

100755100644
File mode changed.

DESCRIPTION

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: hetu
22
Type: Package
33
Title: Structural Handling of Finnish Personal Identity Codes
4-
Version: 1.0.6.9000
5-
Date: 2022-01-18
4+
Version: 1.0.7.9000
5+
Date: 2022-05-16
66
Authors@R:
77
c(
88
person(given = "Pyry",
@@ -41,7 +41,6 @@ URL: https://ropengov.github.io/hetu, https://github.com/ropengov/hetu
4141
Depends:
4242
R (>= 3.6.0)
4343
Imports:
44-
dplyr,
4544
lubridate,
4645
checkmate,
4746
parallel
@@ -50,11 +49,11 @@ Suggests:
5049
knitr,
5150
testthat,
5251
rmarkdown,
53-
covr
54-
RoxygenNote: 7.1.2
52+
covr,
53+
dplyr
54+
RoxygenNote: 7.2.0
5555
X-schema.org-isPartOf: http://ropengov.org/
5656
X-schema.org-keywords: ropengov
5757
Config/Needs/website:
5858
magick,
5959
ropengov/rogtemplate
60-

NAMESPACE

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export(satu_ctrl)
2323
importFrom(checkmate,assert_choice)
2424
importFrom(checkmate,assert_date)
2525
importFrom(checkmate,assert_double)
26-
importFrom(dplyr,filter)
2726
importFrom(lubridate,days)
2827
importFrom(lubridate,interval)
2928
importFrom(lubridate,period)

NEWS.md

100755100644
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# *News*
22
==========
33

4+
# hetu 1.0.7.9000 (2022-05-16)
5+
6+
* subsetting-parameter (TRUE or FALSE) dropped from `hetu_diagnostic()` function as it was unnecessary syntactic sugar that was difficult to communicate to users. Similar functionalities can be easily achieved with standard subsetting functionalities found in base R and especially in tidyverse.
7+
* `satu_ctrl_char()` parameter for printing whole SATU/FINUID-numbers is now called "print.full" instead of "complement".
8+
49
# hetu 1.0.6.9000 (2022-01-18)
510

611
* Rewritten `rpin()` function for increased speed
712
* Added new function `hetu_control_char()` both for internal use in other functions as well as convenience (sometimes you know the rest of the identity code and just need to determine the control character)
813
* Added support for checking the validity of Finnish electronic Unique Identification Numbers (SATU / FINUID). Two new functions: `satu_ctrl()` and `satu_ctrl_char()`, the former works like `hetu_ctrl()` and the latter works like abovementioned `hetu_control_char()`
9-
* `hetu()` table column name checksum changed to more descriptive ctrl.char. The change also affects related column names in `hetu_diagnostic()`
14+
* `hetu()` table column name checksum changed to more descriptive ctrl.char. The change also affects related column names in `hetu_diagnostic()`. This is to illustrate the point that Finnish personal identity code has control characters (numbers and letters) instead of check digits.
1015

1116
# hetu 1.0.3 (2021-07-28)
1217

R/hetu-deprecated.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
#' available at \code{help("-deprecated")}.
77
#' @name hetu-deprecated
88
#' @keywords internal
9-
NULL
9+
NULL

R/hetu.R

100755100644
+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
#' hetu(c("010101-0101", "111111-111C"))
4949
#' # Process a vector of hetu's and extract sex information from each
5050
#' hetu(c("010101-0101", "111111-111C"), extract="sex")
51-
#'
51+
#'
5252
#' @importFrom checkmate assert_choice
53-
#'
53+
#'
5454
#' @export
5555
hetu <- function(pin, extract = NULL, allow.temp = FALSE, diagnostic = FALSE) {
5656

R/hetu_control_char.R

+42-39
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#' @title Finnish Personal Identification Number Control Character Calculator
2-
#' @description Calculate a valid control character for an incomplete
2+
#' @description Calculate a valid control character for an incomplete
33
#' Finnish personal identification numbers (hetu).
44
#' @param pin An incomplete PIN that ONLY has a date, century marker (optional,
55
#' see parameter with.century) and personal number
6-
#' @param with.century If TRUE (default), the function assumes that the PIN
7-
#' input contains a century marker (DDMMYYQZZZ). If FALSE, the function
6+
#' @param with.century If TRUE (default), the function assumes that the PIN
7+
#' input contains a century marker (DDMMYYQZZZ). If FALSE, the function
88
#' assumes that the PIN contains only date and personal number (DDMMYYZZZ).
99
#' @details This method of calculating the control character was devised by
10-
#' mathematician Erkki Pale (1962) to detect input errors but also to
11-
#' detect errors produced by early punch card machines. The long number
10+
#' mathematician Erkki Pale (1962) to detect input errors but also to
11+
#' detect errors produced by early punch card machines. The long number
1212
#' produced by writing the birth date and the personal number together are
1313
#' divided by 31 and the remainder is used to look up the control character
1414
#' from a separate table containing alphanumeric characters except letters
1515
#' G, I, O, Q and Z.
16-
#'
17-
#' The method of calculating the control character does not need century
16+
#'
17+
#' The method of calculating the control character does not need century
1818
#' character and therefore the function has an option to omit it.
1919
#' @return Control character, either a number 0-9 or a letter.
2020
#' @author Pyry Kantanen
@@ -25,103 +25,106 @@
2525
#' hetu_control_char("010101010", with.century = FALSE)
2626
#' @export
2727
hetu_control_char <- function(pin, with.century = TRUE) {
28-
29-
if (length(pin) > 1){
28+
29+
if (length(pin) > 1) {
3030
x <- vapply(pin,
3131
FUN = hetu_control_char,
3232
with.century = with.century,
3333
FUN.VALUE = character(1),
3434
USE.NAMES = FALSE)
3535
return(x)
3636
}
37-
37+
3838
checklist <- c("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
3939
"A", "B", "C", "D", "E", "F", "H", "J", "K", "L",
4040
"M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y")
4141
names(checklist) <- 0:30
42-
43-
if (with.century == TRUE){
44-
if (nchar(pin) != 10){
42+
43+
if (with.century == TRUE) {
44+
if (nchar(pin) != 10) {
4545
stop("Input PINs that only have 10 characters: birthdate, century marker
4646
and personal numbers (DDMMYYQZZZ)")
4747
}
48-
if (!(substr(pin, start = 7, stop = 7) %in% c("-", "+", "A"))){
48+
if (!(substr(pin, start = 7, stop = 7) %in% c("-", "+", "A"))) {
4949
stop("7th character of your PIN needs to be a century marker (-, + or A).
5050
If your PIN does not have it use parameter with.century == FALSE")
5151
}
5252
pin_ddmmyy <- substr(pin, 1, 6)
5353
pin_zzz <- substr(pin, 8, 10)
54-
} else if (with.century == FALSE){
55-
if (nchar(pin) != 9){
54+
} else if (with.century == FALSE) {
55+
if (nchar(pin) != 9) {
5656
stop("Input PINs that only have 9 characters: birthdate and personal
5757
numbers (DDMMYYZZZ)")
5858
}
5959
pin_ddmmyy <- substr(pin, 1, 6)
6060
pin_zzz <- substr(pin, 7, 9)
6161
}
62-
62+
6363
mod <- as.numeric(paste0(pin_ddmmyy, pin_zzz)) %% 31
6464
extracted_control_char <- checklist[as.character(mod)]
6565
names(extracted_control_char) <- NULL
6666
extracted_control_char
67-
67+
6868
}
6969

7070
#' @title Finnish Unique Identification Number Control Character Calculator
71-
#' @description Calculate a valid control character for an incomplete
71+
#' @description Calculate a valid control character for an incomplete
7272
#' Finnish Unique Identification Number (FINUID, or sähköinen asiointitunnus
7373
#' SATU).
74-
#' @param pin An incomplete FINUID that has 8 numbers
75-
#' @param complement Should the function print only
74+
#' @param pin An incomplete FINUID that has 8 first numbers.
75+
#' @param print.full Should the function print only the whole FINUID-number
76+
#' (TRUE) or only the control character (FALSE). Default is FALSE.
7677
#' @details This method of calculating the control character was devised by
77-
#' mathematician Erkki Pale (1962) to detect input errors but also to
78-
#' detect errors produced by early punch card machines. The long number
78+
#' mathematician Erkki Pale (1962) to detect input errors but also to
79+
#' detect errors produced by early punch card machines. The long number
7980
#' produced by writing the birth date and the personal number together are
8081
#' divided by 31 and the remainder is used to look up the control character
8182
#' from a separate table containing alphanumeric characters except letters
8283
#' G, I, O, Q and Z.
83-
#'
84-
#' The method of calculating the control character does not need century
84+
#'
85+
#' The method of calculating the control character does not need century
8586
#' character and therefore the function has an option to omit it.
86-
#' @return Control character, either a number 0-9 or a letter. If complete
87-
#' is TRUE, then the function returns a complete FINUID / SATU number.
88-
#' @seealso
89-
#' For more detailed information about FINUID, see Finnish Digital and
90-
#' population data services agency website:
87+
#' @return Control character, either a number 0-9 or a letter (length 1
88+
#' character). If parameter print.full is set to TRUE, the function returns
89+
#' a complete FINUID / SATU number (length 9 characters).
90+
#' @seealso
91+
#' For more detailed information about FINUID, see Finnish Digital and
92+
#' population data services agency website:
9193
#' \url{https://dvv.fi/en/citizen-certificate-and-electronic-identity}
9294
#' @author Pyry Kantanen
9395
#' @examples
96+
#' # The first assigned FINUID number, 10000001N.
9497
#' satu_control_char("10000001")
9598
#' @export
96-
satu_control_char <- function(pin, complement = FALSE) {
99+
satu_control_char <- function(pin, print.full = FALSE) {
97100

98-
if (length(pin) > 1){
101+
if (length(pin) > 1) {
99102
x <- vapply(pin,
100103
FUN = satu_control_char,
101-
complement = complement,
104+
print.full = print.full,
102105
FUN.VALUE = character(1),
103106
USE.NAMES = FALSE)
104107
return(x)
105108
}
106-
109+
107110
checklist <- c("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
108111
"A", "B", "C", "D", "E", "F", "H", "J", "K", "L",
109112
"M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y")
110113
names(checklist) <- 0:30
111114

112-
if (nchar(pin) != 8){
115+
if (nchar(pin) != 8) {
113116
stop("Input FINUIDs that have 8 numbers")
114117
}
115-
if (suppressWarnings(is.na(as.numeric(pin))) == TRUE){
118+
if (suppressWarnings(is.na(as.numeric(pin))) == TRUE) {
116119
stop("Input FINUIDs that only have numbers")
117120
}
118-
121+
119122
mod <- as.numeric(pin) %% 31
120123
extracted_control_char <- checklist[as.character(mod)]
121124
names(extracted_control_char) <- NULL
122125
extracted_control_char
123-
124-
if (complement == TRUE){
126+
127+
if (print.full == TRUE) {
125128
paste0(pin, extracted_control_char)
126129
} else {
127130
extracted_control_char

R/hetu_diagnostic.R

+18-35
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,52 @@
11
## hetu_diagnostic.R
22
#' @title Diagnostics Tool for HETU
33
#' @description Produce a data frame of PINs that may require closer scrutiny.
4-
#' @param pin Finnish personal identification number as a character vector,
4+
#' @param pin Finnish personal identification number as a character vector,
55
#' or vector of identification numbers as a character vectors
66
#' @param extract Extract only selected part of the diagnostic information.
77
#' Valid values are "\code{hetu}", "\code{is.temp}", "\code{valid.p.num}",
88
#' "\code{valid.ctrl.char}", "\code{correct.ctrl.char}", "\code{valid.date}",
9-
#' "\code{valid.day}", "\code{valid.month}", "\code{valid.length}",
9+
#' "\code{valid.day}", "\code{valid.month}", "\code{valid.length}",
1010
#' "\code{valid.century}". If \code{NULL} (default), returns all information.
11-
#' @param subsetting Print only PINs where the validity check chosen
12-
#' in \code{extract} returns \code{FALSE}.
1311
#' @return A data.frame containing diagnostic checks about PINs.
1412
#' @examples
15-
#' diagnosis_example <- c("010101-0102", "111111-111Q",
16-
#' "010101B0101", "320101-0101", "011301-0101",
13+
#' diagnosis_example <- c("010101-0102", "111111-111Q",
14+
#' "010101B0101", "320101-0101", "011301-0101",
1715
#' "010101-01010", "010101-0011")
18-
#' ## Print all diagnoses
16+
#' ## Print all diagnostics for various fake personal identity codes
1917
#' hetu_diagnostic(diagnosis_example)
2018
#' # Extract century-related checks
2119
#' hetu_diagnostic(diagnosis_example, extract = "valid.century")
22-
#' # Extract only rows where valid.ctrl.char = FALSE
23-
#' hetu_diagnostic(diagnosis_example, subsetting = TRUE, extract = "valid.day")
24-
#'
25-
#' @importFrom dplyr filter
2620
#'
2721
#' @export
28-
hetu_diagnostic <- function(pin, extract = NULL, subsetting = FALSE) {
29-
30-
diagnostic_params <- c("hetu", "is.temp", "valid.p.num", "valid.ctrl.char",
31-
"correct.ctrl.char", "valid.date", "valid.day", "valid.month",
22+
hetu_diagnostic <- function(pin, extract = NULL) {
23+
24+
diagnostic_params <- c("hetu", "is.temp", "valid.p.num", "valid.ctrl.char",
25+
"correct.ctrl.char", "valid.date", "valid.day", "valid.month",
3226
"valid.year", "valid.length", "valid.century")
33-
27+
3428
if (!is.null(extract)) {
3529
if (!all(extract %in% diagnostic_params)) {
3630
stop("Trying to extract invalid diagnostic(s)")
3731
}
3832
}
39-
33+
34+
diagnostic_table <- hetu(pin, allow.temp = TRUE, diagnostic = TRUE)
35+
4036
if (is.null(extract)) {
41-
output <- subset(hetu(pin,
42-
allow.temp = TRUE,
43-
diagnostic = TRUE),
44-
select = diagnostic_params)
37+
output <- diagnostic_table[, diagnostic_params]
4538
} else {
46-
if (subsetting == TRUE) {
47-
output <- hetu(pin, allow.temp = TRUE, diagnostic = TRUE)
48-
output <- dplyr::filter(output,
49-
eval(parse(text = paste(extract, "== FALSE"))))
50-
}
51-
else {
52-
output <- subset(hetu(pin,
53-
allow.temp = TRUE,
54-
diagnostic = TRUE),
55-
select = c("hetu", extract))
56-
}
39+
output <- diagnostic_table[, c("hetu", extract)]
5740
}
5841
return(output)
5942
}
6043

6144
#' @rdname hetu_diagnostic
6245
#' @examples
63-
#' diagnosis_example <- c("010101-0102", "111111-111Q",
64-
#' "010101B0101", "320101-0101", "011301-0101",
46+
#' diagnosis_example <- c("010101-0102", "111111-111Q",
47+
#' "010101B0101", "320101-0101", "011301-0101",
6548
#' "010101-01010", "010101-0011")
6649
#' ## Print all diagnoses
6750
#' pin_diagnostic(diagnosis_example)
6851
#' @export
69-
pin_diagnostic <- hetu_diagnostic
52+
pin_diagnostic <- hetu_diagnostic

0 commit comments

Comments
 (0)