rOpenGov / sweidnumbr

R package for Structural handling of identity numbers used in the swedish administration such as personal identity numbers (personnummer) and organizational identity numbers (organisationsnummer).
https://ropengov.github.io/sweidnumbr/
Other
8 stars 3 forks source link

Invalid pin_ctrl() & oin_ctrl() doesn't return FALSE #86

Closed janzzon closed 8 years ago

janzzon commented 8 years ago

Functions pin_ctrl() & oin_ctrl() should return FALSE if pin or oin is invalid, but it doesn't.

pin_ctrl("202100-6255")
#> Warning in as.pin.character(pin): Erroneous pin(s) (set to NA).
#> Warning: All formats failed to parse. No formats found.
#> [1] NA

oin_ctrl("121212-1212")
#> Warning: The following personal identity numbers are incorrect: 1
#> Error in FUN(X[[i]], ...): All elements of x must have the same length with 9-12 digits!

When functions is supplied with valid pin or oin numbers, it returns TRUE as supposed.

oin_ctrl("202100-6255")
#> [1] TRUE

pin_ctrl("121212-1212")
#> Assumption: Pin of format YYMMDDNNNC is assumed to be less than 100 years old
#> [1] TRUE

Sessioninfo:

sessionInfo()
#> R version 3.2.2 (2015-08-14)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 7 x64 (build 7601) Service Pack 1
#> 
#> locale:
#> [1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252   
#> [3] LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C                   
#> [5] LC_TIME=Swedish_Sweden.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] sweidnumbr_1.0.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] clipr_0.2.0       magrittr_1.5      formatR_1.2.1    
#>  [4] htmltools_0.3     tools_3.2.2       lubridate_1.5.0  
#>  [7] rmarkdown_0.9.2   stringi_1.0-1     knitr_1.12       
#> [10] digest_0.6.9      reprex_0.0.0.9001 stringr_1.0.0    
#> [13] evaluate_0.8

Version

packageVersion("sweidnumbr")
#> [1] '1.0.0'
MansMeg commented 8 years ago

Hi!

Thanks for your bug report! Maybe it is not clear enough in the documentation, but pin_ctrl() checks if it is a correct pin according to the control number. In you example the very format of the pin is incorrect (only 12 months in a year) an the the function can not parse the pin.

I suggest you use this code to solve your problem.

my_pin <- "202100-6255"
!(is.na(pin_ctrl(my_pin)) || !pin_ctrl("202100-6255"))

But you post has given rise to two other potenitial bugs. Thank you!