Skip to content

Commit d1a1757

Browse files
committed
fix: na checks
1 parent 2463bdd commit d1a1757

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: dsUpload
22
Title: Upload Functions for DataSHIELD Backends
3-
Version: 4.2.0
3+
Version: 4.2.1
44
Authors@R:
55
c(person(given = "Sido",
66
family = "Haakma",

R/reshape_helpers.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ du.check.variables <- function(dict_kind, data_columns, run_mode) {
125125
#' @noRd
126126
du.check.nas <- function(stripped, raw) {
127127

128+
# remove child_id
129+
raw <- raw[-1]
130+
128131
variables_na <- raw[!(raw %in% stripped)]
129132

130133
if (length(variables_na) > 0) {
@@ -208,14 +211,15 @@ du.reshape.generate.yearly.repeated <- function(data, dict_kind) {
208211
long_1 <- yearly_repeated_measures %>% gather(orig_var, value, matched_columns[matched_columns !=
209212
"child_id"], na.rm = TRUE)
210213

211-
du.check.nas(colnames(long_1), colnames(yearly_repeated_measures))
212-
213214
# Create the age_years variable with the regular expression extraction of the year
214215
long_1$age_years <- as.numeric(du.num.extract(long_1$orig_var))
215216

216217
# Here we remove the year indicator from the original variable name
217218
long_1$variable_trunc <- gsub("[[:digit:]]+$", "", long_1$orig_var)
218219

220+
raw <- unique(gsub("[[:digit:]]+$", "", colnames(yearly_repeated_measures)))
221+
du.check.nas(unique(long_1$variable_trunc), raw)
222+
219223
# Use the maditr package for spreading the data again, as tidyverse runs into memory
220224
# issues
221225
long_2 <- dcast(long_1, child_id + age_years ~ variable_trunc, value.var = "value")
@@ -278,8 +282,6 @@ du.reshape.generate.monthly.repeated <- function(data, dict_kind) {
278282

279283
long_1 <- monthly_repeated_measures %>% gather(orig_var, value, matched_columns[matched_columns !=
280284
"child_id"], na.rm = TRUE)
281-
282-
du.check.nas(colnames(long_1), colnames(monthly_repeated_measures))
283285

284286
# Create the age_years and age_months variables with the regular expression
285287
# extraction of the year
@@ -289,6 +291,9 @@ du.reshape.generate.monthly.repeated <- function(data, dict_kind) {
289291
# Here we remove the year indicator from the original variable name
290292
long_1$variable_trunc <- gsub("[[:digit:]]+$", "", long_1$orig_var)
291293

294+
raw <- unique(gsub("[[:digit:]]+$", "", colnames(monthly_repeated_measures)))
295+
du.check.nas(unique(long_1$variable_trunc), raw)
296+
292297
# Use the maditr package for spreading the data again, as tidyverse ruins into memory
293298
# issues
294299
long_2 <- dcast(long_1, child_id + age_years + age_months ~ variable_trunc, value.var = "value")
@@ -352,8 +357,6 @@ du.reshape.generate.weekly.repeated <- function(data, dict_kind) {
352357
long_1 <- weekly_repeated_measures %>% gather(orig_var, value, matched_columns[matched_columns !=
353358
"child_id"], na.rm = TRUE)
354359

355-
du.check.nas(colnames(long_1), colnames(weekly_repeated_measures))
356-
357360
# Create the age_years and age_months variables with the regular expression
358361
# extraction of the year NB - these weekly dta are pregnancy related so child is NOT
359362
# BORN YET ---
@@ -362,6 +365,9 @@ du.reshape.generate.weekly.repeated <- function(data, dict_kind) {
362365

363366
# Here we remove the year indicator from the original variable name
364367
long_1$variable_trunc <- gsub("[[:digit:]]+$", "", long_1$orig_var)
368+
369+
raw <- unique(gsub("[[:digit:]]+$", "", colnames(weekly_repeated_measures)))
370+
du.check.nas(unique(long_1$variable_trunc), raw)
365371

366372
# Use the maditr package for spreading the data again, as tidyverse ruins into memory
367373
# issues
@@ -429,15 +435,16 @@ du.reshape.generate.trimesterly.repeated <- function(data, dict_kind) {
429435

430436
long_1 <- trimesterly_repeated_measures %>% gather(orig_var, value, matched_columns[matched_columns !=
431437
"child_id"], na.rm = TRUE)
432-
433-
du.check.nas(colnames(long_1), colnames(trimesterly_repeated_measures))
434438

435439
# Create the age_years and age_months variables with the regular expression
436440
# extraction of the year
437441
long_1$age_trimester <- as.numeric(du.num.extract(long_1$orig_var))
438442

439443
# Here we remove the year indicator from the original variable name
440444
long_1$variable_trunc <- gsub("[[:digit:]]+$", "", long_1$orig_var)
445+
446+
raw <- unique(gsub("[[:digit:]]+$", "", colnames(trimesterly_repeated_measures)))
447+
du.check.nas(unique(long_1$variable_trunc), raw)
441448

442449
# Use the maditr package for spreading the data again, as tidyverse ruins into memory
443450
# issues

0 commit comments

Comments
 (0)