-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from izaak-jephson/main
Add functions to export wb object without saving and to create template script
- Loading branch information
Showing
4 changed files
with
127 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#' Create Template Script to Output Tables | ||
#' | ||
#' @param filename File to output template script to | ||
#' @export | ||
create_template_output <- function(filename = "template"){ | ||
cat( | ||
"### Functions to amend and add ### | ||
# Create metadata object defining each sheet and specifying which tables to include | ||
build_metadata <- function(){ | ||
create_metadata() %>% | ||
# eg add first sheet with one table | ||
add_sheet_to_metadata( | ||
sheet_name = \"Applications by month\", | ||
sheet_title = \"Application outcomes by month\", | ||
table_names = \"table_1\", | ||
table_notes = c(1,2,3)) %>% | ||
# eg add second sheet with one table | ||
add_sheet_to_metadata( | ||
sheet_name = \"Applications by age and LA\", | ||
sheet_title = \"Application outcomes by age and local authority\", | ||
table_names = c(\"table_2\",\"table_3\"), | ||
table_notes = c(1,2,3)) | ||
# ...etc... | ||
} | ||
# Create list of notes | ||
build_notes <- function(){ | ||
tribble( | ||
~note_number, ~note_text, | ||
\"[note 1]\", \"note text 1\", | ||
\"[note 2]\", \"note text 2\", | ||
\"[note 3]\", \"note text 3\" | ||
) | ||
} | ||
# Create tibble containing tables to output | ||
# name column should correspond to table names in metadata, | ||
# table column contains the table objects themselves | ||
# title column contains title to print above table if more than one table on sheet | ||
# otherwise this column is not used | ||
build_tables <- function(){ | ||
tribble( | ||
~name, ~table, ~title | ||
\"table_1\", table_1, \"na\", | ||
\"table_2\", table_2, \"Application outcomes by age\", | ||
\"table_3\", table_3, \"Local Authority\" | ||
) | ||
} | ||
### Add to end of pipeline ### | ||
metadata <- build_metadata() | ||
notes_list <- build_notes() | ||
table_data <- build_tables() | ||
# Output tables to file | ||
save_output_tables( | ||
metadata = metadata, | ||
table_data = table_data, | ||
notes_list = notes_list, | ||
contents_title = \"Statistical tables as at DATE\", | ||
workbook_filename = FILENAME) | ||
" | ||
, file = paste0(filename,".R"), append = FALSE) | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.