Closed ashwinikalantri closed 3 years ago
Thanks for flagging this. I thought I'd handled this, but--shame on me--perhaps the code didn't make it into the release. Stay tuned.
I can't seem to get this working. get_interviews_for_questionnaire
gives this error:
Error: Problem with `mutate()` column `has_identifying`.
ℹ `has_identifying = length(interviews_df$identifyingData[[dplyr::row_number()]])`.
x no such index at level 2
I tired to isolate the issue but can't seem to understand why we get the error. The mutate function gives error while doing this outside works fine.
script
test <- interviews_df %>%
dplyr::select(id, .data$identifyingData)
test %>% dplyr::mutate(has_identifying = length(a$identifyingData[[dplyr::row_number()]]))
length(test$identifyingData[[1]])
length(test$identifyingData[[70]])
output
> test <- interviews_df %>%
+ dplyr::select(id, .data$identifyingData)
> test %>% dplyr::mutate(has_identifying = length(test$identifyingData[[dplyr::row_number()]]))
Error: Problem with `mutate()` column `has_identifying`.
ℹ `has_identifying = length(test$identifyingData[[dplyr::row_number()]])`.
x no such index at level 2
Run `rlang::last_error()` to see where the error occurred.
> length(test$identifyingData[[1]])
[1] 0
> length(test$identifyingData[[70]])
[1] 0
Adding rowwise()
seems to be giving the correct output.
test %>%
rowwise() %>%
dplyr::mutate(has_identifying = length(test$identifyingData[[dplyr::row_number()]]))
Thanks for catching and troubleshooting this! For whatever reason, I couldn't reproduce the error on my end. But I understand the problem. Rather than use dplyr::rowwise()
, I'll employ purrr::map_int
, which I find more readable than my computation of length. Your propsal lead me to this solution, by way of this article.
While using
get_interview_for_questionnaire
with a questionnaire that doesn't have identifying data, I get this error:Error: Column 'value' not found in '.data'
.