I am using the osfr package and I'd like to apply the function osf_ls_nodes to every row in my data.
library(osfr)
library(dplyr)
library(purrr)
project_data =
osfr::osf_retrieve_user("qs9fc") %>%
osf_ls_nodes()
project_data %>% ## only applies to first element
osf_ls_files()
#> Warning: This is not a vectorized function. Only the first row of 10 will be
#> used.
#> # A tibble: 2 x 3
#> name id meta
#> <chr> <chr> <list>
#> 1 pre_analysis_plan.html 5e74e7554a60a50569bb5299 <named list [3]>
#> 2 pre_analysis_plan_amendment.docx 5ee79fa0af2627000d4f641c <named list [3]>
when I attempt to use a typical vectorization pattern using the tidyverse the structure of the data changes and this does not work also.
### When I attempt to vectorize the format changes
out <-
project_data %>%
mutate(n = row_number()) %>%
group_split(.keep = F) %>%
map(osf_ls_files)
#> Error in UseMethod("osf_ls_files"): no applicable method for 'osf_ls_files' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
I can see an obvious way to do this with a loop but I was wondering if it was possible to use group_split or comparable function while maintaining the data structure.