Type: | Package |
Title: | Read and Write 'Excel' Sheets into and from List of Data Frames |
Version: | 0.1.0 |
Maintainer: | Gwang-Jin Kim <gwang.jin.kim.phd@gmail.com> |
Description: | Reading and writing sheets of a single 'Excel' file into and from a list of data frames. Eases I/O of tabular data in bioinformatics while keeping them in a human readable format. |
Depends: | openxlsx |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 6.1.1 |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2019-10-10 08:40:32 UTC; josephus |
Author: | Gwang-Jin Kim [aut, cre] |
Repository: | CRAN |
Date/Publication: | 2019-10-11 09:10:02 UTC |
Write a list of data frames into an excel file with each data frame in a new sheet and the list element name as its sheet name.
Description
Write a list of data frames into an excel file with each data frame in a new sheet and the list element name as its sheet name.
Usage
dfs2xlsx(dfs, fpath, rowNames = TRUE, colNames = TRUE)
Arguments
dfs |
A list of data frames (names in the list are the names of the sheets). |
fpath |
A character string representing path and filename of the output. |
rowNames |
A boolean indicating whether the first column of a table in every sheet contains row names of the table. |
colNames |
A boolean indicating whether the first line of a table in every sheet contains a header. |
Value
Nothing. Writes out data frames into specified Excel file.
Examples
df1 <- data.frame(A=c(1, 2), B=c(3, 4))
df2 <- data.frame(C=c(5, 6), D=c(7, 8))
xlsx_fpath <- file.path(tempdir(), "testout.xlsx")
dfs2xlsx(withNames("sheet1", df1, "sheet2", df2), xlsx_fpath)
file.remove(xlsx_fpath)
Helper function for more convenient input (sheet name, data frame, sheet name, data frame, ...).
Description
Helper function for more convenient input (sheet name, data frame, sheet name, data frame, ...).
Usage
withNames(...)
Arguments
... |
alterning arguments: sheet name 1, data frame 1, sheet name 2, data frame 2, ... |
Value
A list of the data frames with the names given each before.
Examples
df1 <- data.frame(A=c(1, 2), B=c(3, 4))
df2 <- data.frame(C=c(5, 6), D=c(7, 8))
xlsx_fpath <- file.path(tempdir(), "testout.xlsx")
dfs2xlsx(withNames("sheet1", df1, "sheet2", df2), xlsx_fpath)
file.remove(xlsx_fpath)
Read-in Excel file (workbook) as a list of data frames.
Description
Read-in Excel file (workbook) as a list of data frames.
Usage
xlsx2dfs(xlsxPath, rowNames = TRUE, colNames = TRUE, ...)
Arguments
xlsxPath |
A path to the Excel file, a character. |
rowNames |
Whether to read-in row names, a boolean. |
colNames |
Whether to read-in column names, a boolean. |
... |
... passed to read.xlsx function in the openxlsx package. |
Value
A list of data frames, each representing a sheet in the Excel file (sheet names are list element names).
Examples
# create example file
df1 <- data.frame(A=c(1, 2), B=c(3, 4))
df2 <- data.frame(C=c(5, 6), D=c(7, 8))
xlsx_fpath <- file.path(tempdir(), "testout.xlsx")
dfs2xlsx(withNames("sheet1", df1, "sheet2", df2), xlsx_fpath)
# read created file
dfs <- xlsx2dfs(xlsx_fpath)
file.remove(xlsx_fpath)