Skip to content

Commit 0447f09

Browse files
author
Gonçalo Marques
committed
June 2026 splash
1 parent f78658e commit 0447f09

15 files changed

Lines changed: 141 additions & 52 deletions

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: lissyrtools
33
Title: Tools for LISSY Jobs
4-
Version: 0.2.3
4+
Version: 0.2.4
55
Authors@R: c(
66
person("Gonçalo", "Marques", , "marques@lisdatacenter.org", role = c("aut", "cre")),
77
person("Josep", "Espasa Reig" , ,"jespasareig@gmail.com", role = c("aut"))

NEWS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# lissyrtools
22

3+
# lissyrtools 0.2.4 (2026-06-15)
4+
5+
## New functions
6+
## Major changes
7+
8+
- Added a new character argument `pattern` to `variable_labels()`.
9+
10+
## Minor changes
11+
12+
- Bug fix in the body of `structure_to_plot()`.
13+
- The complementary table `lissyrtools::missing_or_zero_vars_all` is now created in a more efficient way and includes a `cname` column.
14+
- Output of `variable_has_note()` and `variable_exists()` now displays country names and not their iso2 codes.
15+
16+
317
# lissyrtools 0.2.3 (2026-03-15)
418

519
## New functions

R/countries_and_years.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ get_countries_lis <- function() {
1313
dplyr::select(cname, iso2) %>%
1414
tibble::deframe()
1515

16-
attributes(output)[1] <- NULL
16+
#attributes(output)[1] <- NULL
1717

1818
return(output)
1919
}
@@ -34,7 +34,7 @@ get_countries_lws <- function() {
3434
dplyr::select(cname, iso2) %>%
3535
tibble::deframe()
3636

37-
attributes(output)[1] <- NULL
37+
#attributes(output)[1] <- NULL
3838

3939
return(output)
4040
}
@@ -81,7 +81,7 @@ get_years_lis <- function(iso2) {
8181
dplyr::arrange(year) %>%
8282
dplyr::pull()
8383

84-
attributes(years_to_output)[1] <- NULL
84+
#attributes(years_to_output)[1] <- NULL
8585

8686
return(years_to_output)
8787
}
@@ -134,7 +134,7 @@ get_years_lws <- function(iso2) {
134134
dplyr::arrange(year) %>%
135135
dplyr::pull()
136136

137-
attributes(years_to_output)[1] <- NULL
137+
#attributes(years_to_output)[1] <- NULL
138138

139139
return(years_to_output)
140140
}

R/data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#'
4545
#' A data frame that identifies whether a variable consists only of zeros or missing values for a given country and year.
4646
#'
47-
#' @format A data frame with 6 variables:
47+
#' @format A data frame with 7 variables:
4848
"missing_or_zero_vars_all"
4949

5050

R/get_labels_notes_surveys.R

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
#' Inspect the Labels of LIS and LWS variables
22
#'
33
#' @param vars A character vector containing LIS/LWS variables or the output list from lissyuse.
4+
#' @param pattern A character.
45
#'
5-
#' @return A character vector with the corresponding labels for the selected variables.
6+
#' @return A character vector with the corresponding labels for the selected variables, or where the pattern was detected in its label.
67
#' @export
78
#'
89
#' @examples
10+
#' \dontrun{
911
#' # 1) Without any argument:
1012
#' variable_labels()
1113
#'
12-
#' \dontrun{
14+
1315
#' # 2) Using with the outputed list from lissyuse:
1416
#' lis_datasets <- lissyuse(data = c("uk"), vars = c("hpub_i","hpub_u", "hi42", "hi421", "hi422", "hi43"), from = 2016)
1517
#' variable_labels(vars = lis_datasets)
16-
#' }
18+
1719
#'
1820
#' # 3) Using a character vector with LIS/LWS variables:
1921
#' variable_labels(vars = c("fyft", "basb", "hxremit", "bafi1_c", "pasodc"))
20-
variable_labels <- function(vars = NULL) {
21-
22-
if (is.null(vars)) {
22+
#'
23+
#' # 4) Using pattern argument:
24+
#' variable_labels(pattern = "occupa")
25+
#' variable_labels(pattern = "capital")
26+
#' }
27+
variable_labels <- function(vars = NULL, pattern = NULL) {
28+
if (is.null(vars) & is.null(pattern)) {
2329
output <- tibble::deframe(lissyrtools::data_vars_labels)
2430
return(output)
2531
} else if (!(is.null(vars))) {
@@ -58,6 +64,22 @@ variable_labels <- function(vars = NULL) {
5864
return(output)
5965
}
6066
}
67+
} else if (!(is.null(pattern))) {
68+
if (!is.character(pattern)) {
69+
stop(glue::glue(
70+
"Argument `pattern` only accepts characters."
71+
))
72+
} else {
73+
output <- lissyrtools::data_vars_labels[
74+
stringr::str_detect(
75+
lissyrtools::data_vars_labels$label,
76+
pattern = pattern
77+
),
78+
] %>%
79+
tibble::deframe()
80+
81+
return(output)
82+
}
6183
}
6284
}
6385

@@ -73,20 +95,23 @@ variable_labels <- function(vars = NULL) {
7395
#' @examples
7496
#' variable_has_note(variable = "area_c", iso2 = "br")
7597
#' variable_has_note(variable = "basb", iso2 = c("fr", "de", "us", "uk"), lws = TRUE)
98+
#'
99+
#' To check the notes on METIS go to: https://www.lisdatacenter.org/frontend#/home, and select a database and a given country:.
100+
#' Afterwards, head to 'RESULTS' > 'Dataset information' > 'Code Books'.
76101
variable_has_note <- function(variable, iso2, lws = FALSE) {
77102

78103
# Ensure that argument 'variable' only accepts one character
79-
104+
80105
if (length(variable) > 1) {
81106
stop(
82107
glue::glue(
83108
"Argument `variable` accepts no more than one character."
84109
)
85110
)
86111
}
87-
112+
88113
# Ensure the validity of the variable
89-
114+
90115
if (lws) {
91116
invalid_var <- variable[!variable %in% lissyrtools::lws_variables]
92117
if (length(invalid_var) > 0) {
@@ -102,17 +127,17 @@ variable_has_note <- function(variable, iso2, lws = FALSE) {
102127
))
103128
}
104129
}
105-
130+
106131
# Ensure the validity of the iso2 codes
107-
132+
108133
valid_iso2 <- if (lws) {
109134
lissyrtools::get_countries_lws()
110135
} else {
111136
lissyrtools::get_countries_lis()
112137
}
113-
138+
114139
invalid_iso2 <- iso2[!iso2 %in% valid_iso2]
115-
140+
116141
if (length(invalid_iso2) == length(iso2)) {
117142
# If no valid iso2 codes, stop with an error
118143
stop(
@@ -130,7 +155,7 @@ variable_has_note <- function(variable, iso2, lws = FALSE) {
130155
)
131156
)
132157
}
133-
158+
134159
# body of the function
135160
process_country <- function(i) {
136161
db <- if (lws) "LWS" else "LIS"
@@ -139,23 +164,40 @@ variable_has_note <- function(variable, iso2, lws = FALSE) {
139164
} else {
140165
lissyrtools::get_years_lis
141166
}
142-
167+
143168
years <- get_years_function(i)[[1]]
144-
169+
145170
existing_years <- lissyrtools::data_with_warnings %>%
146171
dplyr::filter(database == db, iso2 == i, var_name == variable) %>%
147172
dplyr::pull(year)
148-
173+
149174
year_status <- ifelse(years %in% existing_years, "Yes", "No")
150175
names(year_status) <- years
151176
return(year_status)
152177
}
153-
178+
154179
to_be_used_iso2 <- iso2[iso2 %in% valid_iso2]
155180
result <- purrr::map(to_be_used_iso2, process_country)
156-
names(result) <- to_be_used_iso2
157-
181+
182+
183+
# Naming the list
184+
naming_funct <- function(x) {
185+
186+
vector_out <- c()
187+
188+
for (i in to_be_used_iso2) {
189+
country_idx <- lissyrtools::metis_countries_df %>% dplyr::filter(iso2 == i) %>% dplyr::select(name) %>% dplyr::pull()
190+
vector_out[i] <- country_idx
191+
}
192+
vector_out <- unname(vector_out)
193+
194+
return(vector_out)
195+
}
196+
197+
names(result) <- naming_funct(to_be_used_iso2)
198+
158199
return(result)
200+
159201
}
160202

161203

R/variable_exists.R

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
variable_exists <- function(variable, iso2, lws = FALSE, share = FALSE) {
1818

1919
# Ensure that argument 'variable' only accepts one character
20-
20+
2121
if (length(variable) > 1) {
2222
stop(
2323
glue::glue(
2424
"Argument `variable` accepts no more than one character."
2525
)
2626
)
2727
}
28-
28+
2929
# ensure the validity of the variable
30-
30+
3131
if (lws) {
3232
invalid_var <- variable[!variable %in% lissyrtools::lws_variables]
3333
if (length(invalid_var) > 0) {
@@ -43,17 +43,17 @@ variable_exists <- function(variable, iso2, lws = FALSE, share = FALSE) {
4343
))
4444
}
4545
}
46-
46+
4747
# ensure the validity of the iso2 codes
48-
48+
4949
valid_iso2 <- if (lws) {
5050
lissyrtools::get_countries_lws()
5151
} else {
5252
lissyrtools::get_countries_lis()
5353
}
54-
54+
5555
invalid_iso2 <- iso2[!iso2 %in% valid_iso2]
56-
56+
5757
if (length(invalid_iso2) == length(iso2)) {
5858
# If no valid iso2 codes, stop with an error
5959
stop(
@@ -71,7 +71,7 @@ variable_exists <- function(variable, iso2, lws = FALSE, share = FALSE) {
7171
)
7272
)
7373
}
74-
74+
7575
# body of the function
7676
if (share == FALSE) {
7777
process_country <- function(i) {
@@ -81,49 +81,69 @@ variable_exists <- function(variable, iso2, lws = FALSE, share = FALSE) {
8181
} else {
8282
lissyrtools::get_years_lis
8383
}
84-
84+
8585
years <- get_years_function(i)[[1]]
86-
86+
8787
existing_var_years <- lissyrtools::missing_or_zero_vars_all %>%
8888
dplyr::filter(
8989
database == db &
9090
iso2 == i &
9191
variable == {{ variable }} &
92-
status == FALSE
92+
missing_status == FALSE
9393
) %>%
9494
dplyr::pull(year)
95-
95+
9696
year_status <- ifelse(years %in% existing_var_years, "Yes", "No")
9797
names(year_status) <- years
9898
return(year_status)
9999
}
100-
100+
101101
to_be_used_iso2 <- iso2[iso2 %in% valid_iso2]
102102
result <- purrr::map(to_be_used_iso2, process_country)
103-
names(result) <- to_be_used_iso2
104-
103+
104+
# Naming the list
105+
naming_funct <- function(x) {
106+
107+
vector_out <- c()
108+
109+
for (i in to_be_used_iso2) {
110+
country_idx <- lissyrtools::metis_countries_df %>% dplyr::filter(iso2 == i) %>% dplyr::select(name) %>% dplyr::pull()
111+
vector_out[i] <- country_idx
112+
}
113+
vector_out <- unname(vector_out)
114+
115+
return(vector_out)
116+
}
117+
118+
names(result) <- naming_funct(to_be_used_iso2)
119+
105120
return(result)
121+
106122
} else if (share == TRUE) {
123+
107124
db <- if (lws) "LWS" else "LIS"
125+
108126
to_be_used_iso2 <- iso2[iso2 %in% valid_iso2]
109-
127+
110128
share_to_output <- lissyrtools::missing_or_zero_vars_all %>%
111129
dplyr::filter(
112130
database == db,
113131
iso2 %in% to_be_used_iso2,
114132
variable == {{ variable }}
115133
) %>%
116-
dplyr::group_by(iso2, {{ variable }}) %>%
134+
dplyr::group_by(cname, {{ variable }}) %>%
117135
dplyr::summarise(
118-
share = 100 - (sum(status) / dplyr::n() * 100),
136+
share = 100 - (sum(missing_status) / dplyr::n() * 100),
119137
.groups = "drop"
120138
) %>%
121-
dplyr::select(iso2, share) %>%
139+
dplyr::select(cname, share) %>%
122140
dplyr::mutate(share = round(share, digits = 1)) %>%
123141
tibble::deframe()
124-
142+
125143
result <- list()
144+
126145
result[[1]] <- share_to_output
146+
127147
names(result) <- paste0(
128148
"Share of years across the series in ",
129149
dplyr::if_else(lws, "LWS", "LIS"),
@@ -132,5 +152,6 @@ variable_exists <- function(variable, iso2, lws = FALSE, share = FALSE) {
132152
" has values other than zeros and missings."
133153
)
134154
return(result)
155+
135156
}
136-
}
157+
}

data-raw/LWS_income_reference_year_adjustment_data.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ data_inc_ref_year <- tibble::tribble(
2828
"cl17", 2017L,
2929
"cl21", 2021L,
3030
"cl24", 2024L,
31+
"cz21", 2020L,
32+
"fi87", 1987L,
33+
"fi88", 1988L,
34+
"fi94", 1994L,
35+
"fi98", 1998L,
36+
"fi04", 2004L,
3137
"fi09", 2009L,
3238
"fi13", 2013L,
3339
"fi16", 2016L,

data/data_inc_ref_year.rda

31 Bytes
Binary file not shown.

data/data_with_warnings.rda

716 Bytes
Binary file not shown.

data/datasets.rda

72 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)