Skip to content

Commit bb7b652

Browse files
committed
Formatting and deprecation of the .data pronoun
1 parent b0a80ac commit bb7b652

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

vignettes/cap.Rmd

+16-15
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,10 @@ From the metadata description, we select the post-stratification weight variable
9999

100100
```{r weightvars}
101101
weight_variables <- cap_metadata %>%
102-
filter ( .data$var_name_orig %in% c("isocntry", "wex", "wextra", "v47", "v7", "w1") |
103-
.data$var_label_orig %in% c("w_1_weight_result_from_target",
104-
"w_3_weight_special_germany",
105-
"weight_result_from_traget_united_germany",
106-
"w_4_weight_special_united_kingdom",
107-
"weight_result_from_traget_united_kingdom"))
102+
filter (
103+
var_name_orig %in% c("isocntry", "wex", "wextra", "v47", "v7", "w1") | var_label_orig %in% c("w_1_weight_result_from_target",
104+
"w_3_weight_special_germany", "weight_result_from_traget_united_germany", "w_4_weight_special_united_kingdom", "weight_result_from_traget_united_kingdom")
105+
)
108106
```
109107

110108
A *schema crosswalk* is a table that shows equivalent elements (or "fields") in more than one structured data source. With `crosswalk_table_create()` we first create an empty schema crosswalk, then we fill up the empty schema with values. Researchers who feel more comfortable working in a spreadsheet application can create a similar crosswalk table in Excel, Numbers, or OpenOffice, and import the data from a `csv` or any tabular file.
@@ -119,14 +117,16 @@ weigthing_crosswalk_table <- crosswalk_table_create(
119117
# Define the new, harmonized variable names
120118
var_name_target = case_when (
121119
# grepl("weight_result_from_target", .data$val_label_target) ~ "w1", [this is the issue]
122-
.data$var_name_orig %in% c("wex", "wextra", "v47") ~ 'wex',
123-
.data$var_name_orig %in% c("w1", "v8") ~ "w1",
124-
.data$var_name_orig %in% c("w3a", "v12") ~ "w_de",
125-
.data$var_name_orig %in% c("w4a", "v10") ~ "w_uk",
126-
.data$var_name_orig == "rowid" ~ 'rowid', # do not forget to keep the unique row IDs
120+
var_name_orig %in% c("wex", "wextra", "v47") ~ 'wex',
121+
var_name_orig %in% c("w1", "v8") ~ "w1",
122+
var_name_orig %in% c("w3a", "v12") ~ "w_de",
123+
var_name_orig %in% c("w4a", "v10") ~ "w_uk",
124+
var_name_orig == "rowid" ~ 'rowid', # do not forget to keep the unique row IDs
127125
TRUE ~ "geo"),
128126
# Define the target R class for working with these variables.
129-
class_target = ifelse(.data$var_name_target %in% c("geo", "v47"), "factor", "numeric")
127+
class_target = ifelse(var_name_target %in% c("geo", "v47"),
128+
yes = "factor",
129+
no = "numeric")
130130
) %>%
131131
select (
132132
-all_of(c("val_numeric_orig", "val_numeric_target", "val_label_orig", "val_label_target"))
@@ -164,8 +164,8 @@ weight_vars <- weight_vars %>%
164164
country_code == "GB" ~ w_uk, # UK = Great Britain + Northern Ireland
165165
TRUE ~ w1 )) %>%
166166
mutate (year_survey = case_when(
167-
.data$id == "ZA4529_v3-0-1" ~ '2007',
168-
.data$id == "ZA5688_v6-0-0" ~ '2013'
167+
id == "ZA4529_v3-0-1" ~ '2007',
168+
id == "ZA5688_v6-0-0" ~ '2013'
169169
)) %>%
170170
mutate (year_survey = as.factor(.data$year_survey))
171171
```
@@ -174,7 +174,8 @@ weight_vars <- weight_vars %>%
174174

175175
```{r printweigthvars}
176176
weight_vars <- weight_vars %>%
177-
select ( all_of(c("rowid", "country_code", "geo", "w", "w1", "wex", "id")) )
177+
select ( all_of(c("rowid", "country_code", "geo",
178+
"w", "w1", "wex", "id")) )
178179
set.seed(2022)
179180
weight_vars %>% sample_n(6)
180181
```

0 commit comments

Comments
 (0)