saveXLSX: A simple wrapper around 'write.xlsx' from the 'xlsx' package

Description Usage Arguments Details See Also Examples

View source: R/utils.R

Description

A simple wrapper around write.xlsx from the xlsx package

Usage

1
2
saveXLSX(x, file, sheetName = "Sheet1", col.names = TRUE,
  row.names = FALSE, append = FALSE, showNA = FALSE, overwrite = TRUE)

Arguments

x

A data.frame to be saved as a single sheet in an excel file

file

the path to the output file. This should include the '.xlsx' file extension

sheetName

a character string with the sheet name.

col.names

a logical value indicating if the column names of x are to be written along with x to the file.

row.names

a logical value indicating whether the row names of x are to be written along with x to the file.

append

a logical value indicating if x should be appended to an existing file. If TRUE the file is read from disk.

showNA

a logical value. If set to FALSE, NA values will be left as empty cells

overwrite

a logical value indicating if x should overwrite the contents of an existing sheet in the workbook

Details

This function is a basic wrapper around write.xlsx from the xlsx package designed to modify some of the default behaviour. The main difference is the addition of the overwrite argument. This is intended to allow the user to overwrite sheets that already exist in the workbook. If the Excel file specified by file already exists and includes a worksheet with same name as sheetName then this sheet will be deleted and replaced if overwrite=TRUE. If overwrite=FALSE then the sheet is appended to the end of the file.

The default for append in the underlying write.xlsx function is FALSE. If the file you want to write to already exists you should set this to append=TRUE. If the file exists and append=FALSE the existing file will be deleted and replaced. In most cases append=TRUE is probably what you want.

See Also

write.xlsx

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#basic usage for a new file
#creates a temporary file in the current directory
data(iris)
f = paste0('./temp','.xlsx')
saveXLSX(x = iris, file = f, sheetName = 'Test')

#using the same file as above
#use a different data set but keep the same name
#if the file already exists set overwrite = TRUE and append = TRUE
data(CO2)
saveXLSX(x = CO2, file = f, sheetName = 'Test', append = TRUE,
overwrite=TRUE)

#if overwrite = FALSE then the new sheet is appended at
#the end of the file
#use another different data set.
data(Indometh)
saveXLSX(x = Indometh, file = f, sheetName = 'Test', append = TRUE,
overwrite=FALSE)

RichardBirnie/mautils documentation built on July 12, 2019, 8:56 p.m.