Use purrr to make many single one-row tibbles from a larger tibble

I want to slice a n row tibble and make n single one-row tibbles, one tibble for each row. Following that I want to use googlesheets4 to create a new google spreadsheet for each one-row tibble, and use a variable from each tibble row for the google spreadsheet name. Seems like I should use purrr for these steps, but I've thought myself into a circle and could use some tips/help.

In long form this might look like:


mick_df <- band_members %>% 
    slice(n = 1)

john_df <- band_members %>% 
    slice(n = 2)

paul_df <- band_members %>% 
    slice(n = 3)

googlesheets4::gs4_create("mick", sheets = list(sname = mick_df))
googlesheets4::gs4_create("john", sheets = list(sname = john_df))
googlesheets4::gs4_create("paul", sheets = list(sname = paul_df))

# either
(mem_list <- band_members %>% rowwise() %>%

  ~ gs4_create(.$name,
    sheets = list(sname = .))

# or
  ~ {
    f <- slice(band_members, .)
      sheets = list(sname = f))

Many thanks @nirgrahamuk. I learned some new dplyr functions as well. Appreciated!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.