Read/Write sheets (automatically detect the file type and work accordingly)

Usage

read_sheet(x, id_column, start_row = 1, sheet = 1, ext, header = TRUE, verbose = FALSE, ...)
write_sheet(x, file, ext, ...)

Arguments

x
read: path to a file, to be read. write: a data.frame
id_column
all rows which have this column as blank are skipped. See details.
start_row
supplied to read.xlsx
sheet
supplied to read.xlsx, index or name of the sheet to be read from excel file. See read.xlsx
ext
determined using file extention. Specifying will override
header
first line is header? See read.table
verbose
verbosity level.
...
passed onto read.xlsx of openxlsx, read.table or read.csv2 depending on the file type.
file
write: output file name.

Description

Read/Write sheets (automatically detect the file type and work accordingly)

  • tsv, txt, conf, def: assumed to be tab-delimited
  • csv: assumed to be comma delimited
  • xlsx: microsoft excel, uses openxlsx to read the sheet. Also, it removes extra columns which often creep into excel files.

Details

Note: for excel sheets:

  • If id_column is missing, default if first column
  • If sheet is missing, it automatically reads the first sheet

Some important default values for tsv and csv files:

stringsAsFactors = FALSE,comment.char = '#', strip.white=TRUE, blank.lines.skip=TRUE

Examples

## read a excel sheet sheet = read_sheet(system.file("extdata/example.xlsx", package = "params"))
Removing extra columns
## read a comma seperated sheet csv = read_sheet(system.file("extdata/example.csv", package = "params")) ## read a tab seperate sheet tsv = read_sheet(system.file("extdata/example.tsv", package = "params")) # write sheets ------- ## write a comma seperated sheet write_sheet(sheet, "example.csv") ## write a tab seperated sheet write_sheet(sheet, "example.tsv") ## write an excel seperated sheet write_sheet(sheet, "example.xlsx")