@@ -115,7 +115,7 @@ standardize_columns <- function(data,
115
115
116
116
# Reading column standards from a csv-file based on in an Excel file
117
117
if (is.null(standards )) {
118
- column_standards <- utils :: read.csv2(file = paste0(set_dir_NVI(" ProgrammeringR" )," standardization/column_standards.csv" ),
118
+ column_standards <- utils :: read.csv2(file = paste0(NVIdb :: set_dir_NVI(" ProgrammeringR" )," standardization/column_standards.csv" ),
119
119
fileEncoding = " UTF-8" )
120
120
} else {
121
121
column_standards <- standards
@@ -131,10 +131,10 @@ standardize_columns <- function(data,
131
131
132
132
standard <- column_standards %> %
133
133
# Filter to include only information for relevant column names and with property information
134
- poorman :: filter(colname_db %in% columnnames $ V1 ) %> %
135
- poorman :: filter(! is.na(colname )) %> %
136
- poorman :: select(table_db , colname_db , colname ) %> %
137
- poorman :: distinct()
134
+ dplyr :: filter(colname_db %in% columnnames $ V1 ) %> %
135
+ dplyr :: filter(! is.na(colname )) %> %
136
+ dplyr :: select(table_db , colname_db , colname ) %> %
137
+ dplyr :: distinct()
138
138
139
139
# Keep information on relevant table name and combine information for all other tables
140
140
standard [which(standard $ table_db != dbsource ), " table_db" ] <- NA
@@ -143,12 +143,12 @@ standardize_columns <- function(data,
143
143
if (dim(standard )[1 ] > 0 ) {
144
144
standard <- standard %> %
145
145
# Identify column names with only one suggested column width
146
- poorman :: add_count(colname_db , name = " n" ) %> %
147
- poorman :: ungroup() %> %
146
+ dplyr :: add_count(colname_db , name = " n" ) %> %
147
+ dplyr :: ungroup() %> %
148
148
# Select column width either if only one suggested or for the current table
149
- poorman :: filter(n == 1 | table_db == dbsource & n > 1 ) %> %
150
- poorman :: select(colname_db , colname ) %> %
151
- poorman :: distinct()
149
+ dplyr :: filter(n == 1 | table_db == dbsource & n > 1 ) %> %
150
+ dplyr :: select(colname_db , colname ) %> %
151
+ dplyr :: distinct()
152
152
}
153
153
154
154
# # Standardize column names
@@ -218,10 +218,10 @@ standardize_columns <- function(data,
218
218
# Standard labels in Norwegian is always generated as is used to impute missing labels in other languages
219
219
standard <- column_standards %> %
220
220
# Filter to include only information for relevant column names and with property information
221
- poorman :: filter(colname %in% collabels $ V1 ) %> %
222
- poorman :: filter(! is.na(label_1_no )) %> %
223
- poorman :: select(table_db , colname , label_1_no ) %> %
224
- poorman :: distinct()
221
+ dplyr :: filter(colname %in% collabels $ V1 ) %> %
222
+ dplyr :: filter(! is.na(label_1_no )) %> %
223
+ dplyr :: select(table_db , colname , label_1_no ) %> %
224
+ dplyr :: distinct()
225
225
226
226
# Keep information on relevant table name and combine information for all other tables
227
227
standard [which(standard $ table_db != dbsource ), " table_db" ] <- NA
@@ -230,21 +230,21 @@ standardize_columns <- function(data,
230
230
if (dim(standard )[1 ] > 0 ) {
231
231
standard <- standard %> %
232
232
# Identify column names with only one suggested column width
233
- poorman :: add_count(colname , name = " n" ) %> %
234
- poorman :: ungroup() %> %
233
+ dplyr :: add_count(colname , name = " n" ) %> %
234
+ dplyr :: ungroup() %> %
235
235
# Select column width either if only one suggested or for the current table
236
- poorman :: filter(n == 1 | table_db == dbsource & n > 1 ) %> %
237
- poorman :: select(colname = colname , label = label_1_no ) %> %
238
- poorman :: distinct()
236
+ dplyr :: filter(n == 1 | table_db == dbsource & n > 1 ) %> %
237
+ dplyr :: select(colname = colname , label = label_1_no ) %> %
238
+ dplyr :: distinct()
239
239
}
240
240
241
241
# # English column labels ----
242
242
if (language == " en" ) {
243
243
standard_en <- column_standards %> %
244
- poorman :: filter(colname %in% collabels $ V1 ) %> %
245
- poorman :: filter(! is.na(label_1_en )) %> %
246
- poorman :: select(table_db , colname , label_1_en ) %> %
247
- poorman :: distinct()
244
+ dplyr :: filter(colname %in% collabels $ V1 ) %> %
245
+ dplyr :: filter(! is.na(label_1_en )) %> %
246
+ dplyr :: select(table_db , colname , label_1_en ) %> %
247
+ dplyr :: distinct()
248
248
249
249
# Keep information on relevant table name and combine information for all other tables
250
250
standard_en [which(standard_en $ table_db != dbsource ), " table_db" ] <- NA
@@ -253,18 +253,18 @@ standardize_columns <- function(data,
253
253
if (dim(standard_en )[1 ] > 0 ) {
254
254
standard_en <- standard_en %> %
255
255
# Identify column names with only one suggested column width
256
- poorman :: add_count(colname , name = " n" ) %> %
257
- poorman :: ungroup() %> %
258
- poorman :: filter(n == 1 | table_db == dbsource & n > 1 ) %> %
259
- poorman :: select(colname , label_1_en ) %> %
260
- poorman :: distinct()
256
+ dplyr :: add_count(colname , name = " n" ) %> %
257
+ dplyr :: ungroup() %> %
258
+ dplyr :: filter(n == 1 | table_db == dbsource & n > 1 ) %> %
259
+ dplyr :: select(colname , label_1_en ) %> %
260
+ dplyr :: distinct()
261
261
}
262
262
263
263
# Impute missing labels with Norwegian labels
264
264
standard <- standard_en %> %
265
- poorman :: full_join(standard , by = c(" colname" = " colname" )) %> %
266
- poorman :: mutate(label = poorman :: coalesce(label_1_en , label )) %> %
267
- poorman :: select(colname , label )
265
+ dplyr :: full_join(standard , by = c(" colname" = " colname" )) %> %
266
+ dplyr :: mutate(label = dplyr :: coalesce(label_1_en , label )) %> %
267
+ dplyr :: select(colname , label )
268
268
}
269
269
270
270
# # Impute Sentence case for those without defined label ----¨
@@ -302,13 +302,13 @@ standardize_columns <- function(data,
302
302
# Standardize colwidths
303
303
standard <- column_standards %> %
304
304
# Filter to include only information for relevant column names and with property information
305
- poorman :: filter(colname %in% colwidths $ V1 ) %> %
306
- poorman :: filter(! is.na(colwidth_Excel )) %> %
307
- poorman :: select(table_db = table_db , colname = colname , colwidth = colwidth_Excel )
305
+ dplyr :: filter(colname %in% colwidths $ V1 ) %> %
306
+ dplyr :: filter(! is.na(colwidth_Excel )) %> %
307
+ dplyr :: select(table_db = table_db , colname = colname , colwidth = colwidth_Excel )
308
308
# uses which below as there seem to be a bug so that case_when doesn't work properly within a function
309
- # poorman ::mutate(table_db = poorman ::case_when(table_db == "dbsource" ~ table_db,
309
+ # dplyr ::mutate(table_db = dplyr ::case_when(table_db == "dbsource" ~ table_db,
310
310
# TRUE ~ as.character(NA))) %>%
311
- # poorman ::distinct()
311
+ # dplyr ::distinct()
312
312
# Keep information on relevant table name and combine information for all other tables
313
313
standard [which(standard $ table_db != dbsource ), " table_db" ] <- NA
314
314
standard <- unique(standard )
@@ -317,12 +317,12 @@ standardize_columns <- function(data,
317
317
if (dim(standard )[1 ] > 0 ) {
318
318
standard <- standard %> %
319
319
# Identify column names with only one suggested column width
320
- poorman :: add_count(colname , name = " n" ) %> %
321
- poorman :: ungroup() %> %
320
+ dplyr :: add_count(colname , name = " n" ) %> %
321
+ dplyr :: ungroup() %> %
322
322
# Select column width either if only one suggested or for the current table
323
- poorman :: filter(n == 1 | table_db == dbsource & n > 1 ) %> %
324
- poorman :: select(colname , colwidth ) %> %
325
- poorman :: distinct()
323
+ dplyr :: filter(n == 1 | table_db == dbsource & n > 1 ) %> %
324
+ dplyr :: select(colname , colwidth ) %> %
325
+ dplyr :: distinct()
326
326
}
327
327
328
328
# New column with standard column names¨
@@ -356,17 +356,17 @@ standardize_columns <- function(data,
356
356
# Standard labels in Norwegian is always generated as is used to impute missing labels in other languages
357
357
standard <- column_standards %> %
358
358
# Filter to include only information for relevant column names and with property information
359
- poorman :: filter(table_db == dbsource ) %> %
360
- poorman :: filter(colname %in% columnorder $ V1 ) %> %
361
- poorman :: filter(! is.na(colorder )) %> %
362
- poorman :: select(colname , colorder ) %> %
363
- poorman :: distinct() %> %
359
+ dplyr :: filter(table_db == dbsource ) %> %
360
+ dplyr :: filter(colname %in% columnorder $ V1 ) %> %
361
+ dplyr :: filter(! is.na(colorder )) %> %
362
+ dplyr :: select(colname , colorder ) %> %
363
+ dplyr :: distinct() %> %
364
364
# removes colorders with more than suggested position
365
- poorman :: add_count(colname , name = " n" ) %> %
366
- poorman :: filter(n == 1 ) %> %
367
- poorman :: select(colname , colorder )
365
+ dplyr :: add_count(colname , name = " n" ) %> %
366
+ dplyr :: filter(n == 1 ) %> %
367
+ dplyr :: select(colname , colorder )
368
368
# Sort according to first column, replaced by order
369
- # poorman ::arrange(colorder)
369
+ # dplyr ::arrange(colorder)
370
370
371
371
standard <- standard [order(standard $ colorder ),]
372
372
0 commit comments