Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use getSurveyInstancesBulk 'id_to_field_name' argument #55

Open
cretecht opened this issue Aug 30, 2024 · 2 comments
Open

How to use getSurveyInstancesBulk 'id_to_field_name' argument #55

cretecht opened this issue Aug 30, 2024 · 2 comments

Comments

@cretecht
Copy link

cretecht commented Aug 30, 2024

I'm trying to import survey instances. The data.frame has all of the relevant data, but not the field variable names. It has the field ids instead. I notice the id_to_field_name argument defaults to NULL. I assume it can be used to retrieve the field variable names. In the source code, the id_to_field_name is a list with the indices as field ids (below is the code I'm referring to in CastorData.R, lines 421-428), but when comparing the field ids in the getSurveyInstancesBulk with the field ids in the getFields output, there's no overlap or identical field ids.

# Get survey field ids and names to later clean up the split dataframes survey_field_id <- survey_instances %>% dplyr::select(field_id, survey_name) %>% distinct() %>% rowwise() %>% mutate(field_name = id_to_field_name_[[field_id]]) %>% dplyr::select(-field_id) %>% ungroup()

I also constructed an indexed list with field ids as indices and elements as field variable names, but to no avail (code below).

fields <- castor_api$getFields(study_id = "study id") voi_field_ids <- fields %>% filter(grepl("Variable of Interest", field_variable_name) & (grepl("Week", field_variable_name) | grepl("Month", field_variable_name))) %>% dplyr::select(field_id, field_variable_name) voi_field_ids_list <- voi_field_ids %>% as.list() voi_id_to_fieldname <- list() for (i in 1:dim(voi_field_ids)[1]){ field_id <- voi_field_ids_list[['field_id']][i] field_variable_name <- voi_field_ids_list[['field_variable_name']][i] voi_id_to_fieldname[[field_id]] <- field_variable_name } voi_id_to_fieldname castor_api$getSurveyInstancesBulk(study_id = "study id", id_to_field_name = voi_id_to_fieldname)

I receive the error traceback below when I implement the above chunk.

Error in rename():
! All renaming inputs must be named.
Backtrace: 1. castor_api$getSurveyInstancesBulk(...) 2. dplyr::rename_at(...) 4. dplyr:::rename.data.frame(.tbl, !!!syms)

How can the field variable names be imported with the survey instances data? Is there a specific way to do so?

@cretecht
Copy link
Author

An update: using simply a list with field variable names as its outputted with getFields results in the same error.

@cretecht
Copy link
Author

cretecht commented Sep 4, 2024

@martijnkersloot Is there any update on a solution for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant