Skip to content

Read and Write 'Excel' Sheets into and from List of Data Frames

License

Notifications You must be signed in to change notification settings

gwangjinkim/xlsx2dfs

Repository files navigation

xlsx2dfs

xlsx2dfs: Reading/Writing Excel File Sheets from/to List of Data Frames

This is the official repository of my first R package `xlsx2dfs` which I uploaded to CRAN.

Installation

install.packages("xlsx2dfs")

or:

devtools::install_github("gwangjinkim/xlsx2dfs")

In case of the error:

## sh: 1: /bin/gtar: not found

do:

Sys.setenv(TAR = "/bin/tar") # or wherever your TAR is - find out by: `$ which tar`
devtools::install_github("gwangjinkim/xlsx2dfs")

Usage

This package is a wrapper for `openxlsx`. It reads entire excel files with all their sheets into a list of data frames (one data frame for each sheet, one list of data frame for one excel file). For creating an excel file, put together all your data frames into a list and give them names for the sheet titles. The `withNames()` function helps during the input by making it possible to alternate name and data frame.

library(xlsx2dfs)
df1 <- data.frame(genes = c("gene1", "gene2"),
                  count = c(23,  50))
df2 <- data.frame(genes = c("gene3", "gene4"),
                  count = c(100, 500))
# write one data frame on one sheet
dfs2xlsx(withNames("first sheet", df1), "../inst/extdata/test_one_df.xlsx")

# write more data frames into one file
dfs2xlsx(withNames("first data frame", df1,
                   "second data frame", df2), "../inst/extdata/test_two_dfs.xlsx")

# or create a data frame list with the desired names
# and print into xlsx file
dfs <- list(`first data frame`=df1,
            `second data frame`=df2)
# actually "withNames()" is superfluous ...
dfs2xlsx(dfs, "../inst/extdata/test_two_dfs1.xlsx")

# write one data frame into a file
dfs2xlsx(list(`one data frame`=df1),
         "../inst/extdata/one_df.xlsx")

# read-in excel file as a data frame list
dfs <- xlsx2dfs("../inst/extdata/test_two_dfs1.xlsx")

About

Read and Write 'Excel' Sheets into and from List of Data Frames

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages