SwissStatsR / noga

R Package to recode noga values and labels
GNU General Public License v3.0
0 stars 2 forks source link

Improve level detection when some names are shared between classes and types #20

Closed raphbub-vs closed 2 months ago

raphbub-vs commented 3 months ago

In the case where some labels are common between the class and the type (ex. 0112 and 011200 "Growing of rice") among a set of "type labels", the detected level is still "class".

For example :

library(noga)
type_labels <- c("Growing of other non-perennial crops", "Growing of grapes", "Manufacture of cheese")
automaticleveldetection(type_labels , "en")
# "class"
noga_recode(type_labels, level = "type")
# "011900" "012101" "105102" (correct)
# Warning message:
# In noga_recode(type_labels, level = "type") :
# The noga level you have supplied manually in the level parameter
# does not correspond to the automatically detected noga level [...]

In automaticleveldetection, the lookup table is filtered like this for those types :

code section division group class type name_en
0119 A 01 011 0119 NA Growing of other non-perennial crops
011900 A 01 011 0119 011900 Growing of other non-perennial crops
0121 A 01 012 0121 NA Growing of grapes
012101 A 01 012 0121 012101 Growing of grapes
105102 C 10 105 1051 105102 Manufacture of cheese

As there are NAs in the types, only the class is retained despite the types being all present.

raphbub-vs commented 3 months ago

The warning message should be adapted with the new repo address (+fix the typo for variable).

Current message : The noga level you have supplied manually in the level parameter does not correspond to the automatically detected noga level of the input variable. Expect weird output. If you think the noga level you have supplied does match the one of the varaible and that this is a bug of this function, please open an issue at https://github.com/jbeoh/noga/issues