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

potential bug in cb_get_participants_table? #81

Open
hms1 opened this issue Jan 27, 2022 · 0 comments
Open

potential bug in cb_get_participants_table? #81

hms1 opened this issue Jan 27, 2022 · 0 comments

Comments

@hms1
Copy link

hms1 commented Jan 27, 2022

While reviewing #80 I noticed a potential bug in cb_get_participants_table. Using the relevant branch:

library(cloudos)

cohortv2 <- cb_load_cohort("61f1bd4b3de81e52ec46d0ea")
cb_get_participants_table(cohortv2)
 Error: All elements must be size one, use `list()` to wrap.
x Element `f4i0a0` is of size 0.
Run `rlang::last_error()` to see where the error occurred.

It looks like the error is happening here:

for (n in c(list(emptyrow), res$data)) {
# important to change NULL to NA using .null_to_na_nested
dta <- .null_to_na_nested(n)
# change types within lists according to col_type
for (name in names(dta)) {
if (is.list(dta[[name]])){
type_func <- col_types[[name]]
dta[[name]] <- list(type_func(dta[[name]]))
}
}
dta <- tibble::as_tibble_row(dta)
df_list <- c(df_list, list(dta))
}

I am not familiar with this code, so someone with a better understanding should look properly, but it appears it can be fixed using something like:

  for (dta in c(list(emptyrow), res$data)) {
    # drop all null elements entirely
    dta[sapply(dta, is.null)] <- NULL
    # change types according to col_type
    for (name in names(dta)) {
      type_func <- col_types[[name]]
      dta[[name]] <- type_func(dta[[name]])
    }
    dta <- tibble::as_tibble_row(dta)
    df_list <- c(df_list, list(dta))
  }
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