Skip to content

Commit 1fa6b85

Browse files
committed
Fix gender F misinterpreted as boolean FALSE
1 parent 6e34984 commit 1fa6b85

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

R/add_responses.R

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,33 @@ add_responses <- function(iSurveyID, data, verbose = FALSE) {
4444
# data <- data %>%
4545
# dplyr::mutate_if(is.numeric, ~tidyr::replace_na(., 0))
4646

47+
convert_column_types <- function(x) {
48+
if (all(!is.na(x), x != "")) {
49+
if (x == "F")
50+
x <- "FEMALE" # Rename for circumvent type.convert
51+
52+
x <- utils::type.convert(x, as.is = TRUE)
53+
54+
if (x == "FEMALE")
55+
x <- "F" # set to original value
56+
}
57+
58+
return(x)
59+
}
60+
4761
res <-
4862
apply(
4963
data,
5064
MARGIN = 1,
5165
FUN = function(x) {
5266
# remove NA Values and blanks
5367
x <- x[!is.na(x)] %>% trimws()
54-
x <- utils::type.convert(as.list(x), as.is = TRUE)
68+
69+
x <- lapply(x, FUN = function(el) convert_column_types(el) )
5570

5671
call_limer("add_response",
57-
params = list("iSurveyID" = iSurveyID,
58-
"aResponseData" = x))
72+
params = list("iSurveyID" = iSurveyID,
73+
"aResponseData" = x))
5974
}
6075
)
6176

0 commit comments

Comments
 (0)