Last active
October 9, 2018 15:00
-
-
Save trinker/6e8f10ed7f37181c64b1fd020560ece9 to your computer and use it in GitHub Desktop.
Write out a bunch of tables to an excel file pipeable workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!require("pacman")) install.packages("pacman"); library(pacman) | |
p_load(tidyverse, openxlsx, magrittr, pander, numform) | |
## make an environment to store everything | |
my_tables <- new.env() | |
## basic boiler plate chunk to add | |
## %T>% | |
## {assign('yearly_billings_and_percent_change', ., envir = my_tables)} | |
## Example table 1 | |
mtcars %>% | |
mutate(perc_disp = disp * 100) %>% | |
head(5) %T>% | |
{assign('mtcars_transformed', ., envir = my_tables)} %>% | |
data.frame(stringsAsFactors = FALSE, check.names = FALSE) %>% | |
pander::pander(split.tables = Inf, justify = numform::alignment(.)) | |
## Example table 2 | |
CO2 %>% | |
mutate( | |
Treatment = abbreviate(Treatment), | |
conc_uptake = conc/uptake | |
) %>% | |
head(5) %T>% | |
{assign('co2_transformed', ., envir = my_tables)} %>% | |
data.frame(stringsAsFactors = FALSE, check.names = FALSE) %>% | |
pander::pander(split.tables = Inf, justify = numform::alignment(.)) | |
## write file to multi tabbes excel | |
as.list(my_tables) %>% | |
openxlsx::write.xlsx('my_analysis_tables.xlsx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment