R/read_ods_sheets.R

Defines functions read_ods_sheets

Documented in read_ods_sheets

#' datatools::read_ods_sheets
#'
#'Import LibreOffice workbook with multiple sheets
#'
#'This function imports multiple sheets contained in a .ods spreadsheet into distinct tibbles.
#'
#' @param path path to the ods file.
#' @param skip An integer: number of rows to be skiped in the beginning of each sheet; default = 0
#' @return A series of tibbles corresponding to the different sheets contained in the Excel workbook.
#' @examples
#' \dontrun{
#' path <- ".../myworkbook.ods"
#' read_ods_sheets(path)
#' read_ods_sheets(path, skip = 2)
#' }
#' @import readODS
#' @export

read_ods_sheets <- function(path, skip = 0){

  sheetnames <- readODS::list_ods_sheets(path) # get sheetnames
  sheetlist <- sapply(sheetnames, function(x){readODS::read_ods(path, sheet = x, skip = 1)})
  for (sh in sheetnames) {
    sheetlist[[sh]] <- tibble:as_tibble(sheetlist[[sh]]) # create list containing each sheet
  }

  list2env(sheetlist, .GlobalEnv) # transfer list to Global Env.
}
pmerckle/datatools documentation built on Feb. 21, 2022, 2:19 a.m.