Selecting multiple ranges in GoogleSheets4 readd_sheets fuction

30 views Asked by At

Is there a way to read in multiple ranges at the same time in GoogleSheets4 read_sheet function?

I've tried all of these with no luck:

DateInfo2022 <- read_sheet('https://docs.google.com/spreadsheets/......',sheet="Dates",range="A2:F37" & "A41:F56")

DateInfo2022 <- read_sheet('https://docs.google.com/spreadsheets/......',sheet="Dates",range="A2:F37", "A41:F56")

DateInfo2022 <- read_sheet('https://docs.google.com/spreadsheets/......',sheet="Dates",range=c("A2:F37", "A41:F56"))

1

There are 1 answers

0
Ben On

One approach is to create a table of sheets and ranges:

my_table <- data.frame(
  sheet = c("MySheet", "MySheet"),
  range = c("A1:B2", "D6:E8")
)

And then use that with mapply to read the individual ranges from the sheets, with the result being a list. This allows for different ranges to be selected of different dimensions.

library(googlesheets4)

mapply(
  read_sheet,
  ss = "<INSERT GOOGLE SHEET URL>",
  sheet = my_table$sheet,
  range = my_table$range,
  SIMPLIFY = FALSE
)