Skip to contents

This function wraps `openxlsx::read.xlsx` and returns the data as a `data.table`.

Usage

xlsxReadData(
  wb,
  sheetName = 1,
  skipDescriptionRow = FALSE,
  alwaysCharacter = c("Group", "Id$", "Ids$"),
  emptyAsNA = TRUE,
  convertHeaders = TRUE
)

Arguments

wb

A workbook object or a character string specifying the path to the xlsx file.

sheetName

A character string specifying the name of the sheet to read.

skipDescriptionRow

A logical value or an integer indicating whether the first row (or rows, if an integer) should be treated as description rows and skipped during reading. When set to TRUE, the first row is skipped; when set to a positive integer, that number of rows will be skipped. The 'Comment' column is also excluded from the resulting data table.

alwaysCharacter

A character vector with column names or regex patterns that should be returned as character (typically identifiers).

emptyAsNA

A logical value. If TRUE, empty strings in character columns are converted to NA. If FALSE NA is returned as empty string. Numeric columns Return always NA

convertHeaders

A logical value. If TRUE, column names are converted to start with a lowercase letter.

Value

A `data.table` containing the sheet data.

See also

Other function to read from and write to xlsx: setHeadersToLowerCase(), splitInputs(), xlsxAddDataUsingTemplate(), xlsxAddSheet(), xlsxCloneAndSet(), xlsxWriteData()

Examples

if (FALSE) { # \dontrun{
wb <- loadWorkbook("example.xlsx")
data <- xlsxReadData(wb, "DataSheet", skipDescriptionRow = 1)
print(data)
} # }