|
8 | 8 | #' microdonnées. |
9 | 9 | #' |
10 | 10 | #' The function reconstructs the variable hierarchy from the levels |
11 | | -#' present in the data. The variables in \code{vars_hrc} must be |
12 | | -#' \strong{classified from the finest to the most aggregated}. |
| 11 | +#' present in the data. The variables in `vars_hrc` must be |
| 12 | +#' **classified from the finest to the most aggregated**. |
13 | 13 | #' |
14 | 14 | #' The relationship between each hierarchical level must be an application (in the |
15 | 15 | #' mathematical sense of the term), i.e. each fine level must have a |
|
22 | 22 | #' |
23 | 23 | #' Missing values in the hierarchical variables will be |
24 | 24 | #' imputed beforehand using another hierarchical variable (parameter |
25 | | -#' \code{fill_na}). In ascending strategy (\code{"up"}), the variables are |
| 25 | +#' `fill_na`). In ascending strategy (`"up"`), the variables are |
26 | 26 | #' from the most aggregated to the most refined, and vice versa in the |
27 | | -#' downward strategy (\code{"down"}). |
| 27 | +#' downward strategy (`"down"`). |
28 | 28 | #' |
29 | | -#' The parameter \code{compact} allows to create hierarchies with variable |
| 29 | +#' The parameter `compact` allows to create hierarchies with variable |
30 | 30 | #' depths. The idea is to cut the branches consisting of a single value |
31 | 31 | #' repeated up to the maximum depth (see examples).\cr |
32 | 32 | #' |
33 | 33 | #' La fonction reconstitue la hiérarchie des variables à partir des niveaux |
34 | | -#' présents dans les données. Les variables dans \code{vars_hrc} doivent être |
35 | | -#' \strong{classées de la plus fine à la plus agrégée}. |
| 34 | +#' présents dans les données. Les variables dans `vars_hrc` doivent être |
| 35 | +#' **classées de la plus fine à la plus agrégée**. |
36 | 36 | #' |
37 | 37 | #' La relation entre chaque niveau hiérarchique doit être une application (au |
38 | 38 | #' sens mathématique du terme), c'est-à-dire que chaque niveau fin doit avoir un |
|
45 | 45 | #' |
46 | 46 | #' Les valeurs manquantes présentes dans les variables hiérarchiques seront |
47 | 47 | #' préalablement imputées à l'aide d'une autre variable hiérarchique (paramètre |
48 | | -#' \code{fill_na}). En stratégie ascendante (\code{"up"}), les variables sont |
| 48 | +#' `fill_na`). En stratégie ascendante (`"up"`), les variables sont |
49 | 49 | #' parcourues de la plus agrégée à la plus fine, et inversement en stratégie |
50 | | -#' descendante (\code{"down"}). |
| 50 | +#' descendante (`"down"`). |
51 | 51 | #' |
52 | | -#' Le paramètre \code{compact} permet de créer des hiérarchies à profondeurs |
| 52 | +#' Le paramètre `compact` permet de créer des hiérarchies à profondeurs |
53 | 53 | #' variables. L'idée est de couper les branches constituées d'une seule valeur |
54 | 54 | #' répétée jusqu'à la profondeur maximale (voir exemples). |
55 | 55 | #' |
56 | 56 | #' @inheritParams micro_asc_rda |
57 | | -#' @param vars_hrc \strong{[mandatory]} vector of variable names |
| 57 | +#' @param vars_hrc vector of variable names |
58 | 58 | #' constituting the hierarchy, from the finest to the most aggregated level.\cr |
59 | | -#' (\strong{[obligatoire]} vecteur des noms des variables |
| 59 | +#' (vecteur des noms des variables |
60 | 60 | #' constituant la hiérarchie, du niveau le plus fin au niveau le plus agrégé.) |
61 | 61 | #' @param hrc_filename name and location of the produced hrc file. If not |
62 | 62 | #' filled, a temporary file.\cr |
63 | 63 | #' (nom et emplacement du fichier hrc produit. Si non renseigné, un fichier temporaire.) |
64 | 64 | #' @param fill_na fill in any missing values, using an other variable : |
65 | 65 | #' \itemize{ |
66 | | -#' \item{\code{"up"} (default) : hierarchical variable of the level level |
| 66 | +#' \item{`"up"` (default) : hierarchical variable of the level level |
67 | 67 | #' immediately above} |
68 | | -#' \item{\code{"down"} : hierarchical variable of the level immediately |
| 68 | +#' \item{`"down"` : hierarchical variable of the level immediately |
69 | 69 | #' lower} |
70 | 70 | #' }\cr |
71 | 71 | #' (remplissage d'éventuelles valeurs manquantes, à l'aide d'une |
72 | 72 | #' autre variable :\itemize{ |
73 | | -#' \item{\code{"up"} (défaut) : variable hiérarchique de niveau |
| 73 | +#' \item{`"up"` (défaut) : variable hiérarchique de niveau |
74 | 74 | #' immédiatement supérieur} |
75 | | -#' \item{\code{"down"} : variable hiérarchique de niveau immédiatement |
| 75 | +#' \item{`"down"` : variable hiérarchique de niveau immédiatement |
76 | 76 | #' inférieur} |
77 | 77 | #' }) |
78 | 78 | #' @param compact to prune branches repeating a single value to the |
79 | | -#' lowest level of depth (\code{TRUE} by default).\cr |
| 79 | +#' lowest level of depth (`TRUE` by default).\cr |
80 | 80 | #' (pour élaguer les branches répétant une unique valeur jusqu'au |
81 | | -#' plus bas niveau de profondeur (\code{TRUE} par défaut).) |
82 | | -#' @param hierlevels if only one variable is specified in \code{vars_hrc}, |
| 81 | +#' plus bas niveau de profondeur (`TRUE` par défaut).) |
| 82 | +#' @param hierlevels if only one variable is specified in `vars_hrc`, |
83 | 83 | #' allows to generate the hierarchy according to the position of the characters in the |
84 | | -#' string. For example, \code{hierlevels = "2 3"} to build a |
| 84 | +#' string. For example, `hierlevels = "2 3"` to build a |
85 | 85 | #' hierarchy from a common code.\cr |
86 | | -#' (si une seule variable est spécifiée dans \code{vars_hrc}, |
| 86 | +#' (si une seule variable est spécifiée dans `vars_hrc`, |
87 | 87 | #' permet de générer la hiérarchie selon la position des caractères dans la |
88 | | -#' chaîne. Par exemple, \code{hierlevels = "2 3"} pour construire une |
| 88 | +#' chaîne. Par exemple, `hierlevels = "2 3"` pour construire une |
89 | 89 | #' hiérarchie département-commune à partir d'un code commune.) |
90 | 90 | #' |
91 | 91 | #' @return The name of the hrc file (useful in the case of a temporary file with |
@@ -446,7 +446,8 @@ df_hierlevels <- function(var_hrc, hierlevels) { |
446 | 446 | } |
447 | 447 |
|
448 | 448 | lev <- strsplit(hierlevels, " +")[[1]] |
449 | | - lev <- as.integer(lev) %>% `[`(. != 0) |
| 449 | + lev <- as.integer(lev) |
| 450 | + lev <- lev[lev != 0] |
450 | 451 | if (sum(lev) != n1) { |
451 | 452 | stop("la somme de hierlevels doit etre egale au nombre de caracteres") |
452 | 453 | } |
|
0 commit comments