Skip to content

Commit

Permalink
update publication functions with test directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 committed Aug 2, 2024
1 parent 364fe18 commit 0315a54
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions code/publication/01_create-pub-basefile.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ create_final_data(

### 2 - Restructure data file ----

basefile <- read_rds(get_mi_data_path(type = "final_data", ext = "rds")) %>%
basefile <- read_rds(get_mi_data_path(type = "final_data", ext = "rds", test_output = test_output)) %>%

# Select only FY to be included in pub
filter(fy %in% fy_in_pub) %>%
Expand Down Expand Up @@ -81,6 +81,6 @@ basefile <- read_rds(get_mi_data_path(type = "final_data", ext = "rds")) %>%

### 3 - Save file ----
basefile %>%
write_rds(get_pub_data_path(), compress = "gz")
write_rds(get_pub_data_path(test_output = test_output), compress = "gz")

### END OF SCRIPT ###
22 changes: 10 additions & 12 deletions code/publication/02_create-figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source(here("functions", "ggplot_themes.R"))

### 2 - Read in data ----

basefile <- read_rds(get_pub_data_path())
basefile <- read_rds(get_pub_data_path(test_output = test_output))


# Load expected diagnoses reference file
Expand Down Expand Up @@ -89,7 +89,7 @@ c1 <-
) +
ylab("")

ggsave(get_pub_figures_path(type = "c1"),
ggsave(get_pub_figures_path(type = "c1", test_output = test_output),
plot = c1,
height = 6,
width = 6,
Expand Down Expand Up @@ -128,7 +128,7 @@ c2 <-
xlab("Percentage of Referrals Achieved LDP Standard") +
ylab("")

ggsave(get_pub_figures_path(type = "c2"),
ggsave(get_pub_figures_path(type = "c2", test_output = test_output),
plot = c2,
height = 6,
width = 6,
Expand All @@ -137,9 +137,7 @@ ggsave(get_pub_figures_path(type = "c2"),
)

# Save chart for twitter
ggsave(
here("publication", "output", pub_date,
paste0(pub_date, "_dementia-pds_twitter-chart.png")),
ggsave(get_pub_figures_path(type = "twitter", test_output = test_output),
plot = c2,
height = 6,
width = 6,
Expand All @@ -158,7 +156,7 @@ summary <-
theme(axis.title.x = element_text(size = 7.5),
axis.text = element_text(size = 7.5))

ggsave(get_pub_figures_path(type = "summary"),
ggsave(get_pub_figures_path(type = "summary", test_output = test_output),
plot = summary,
height = 5,
width = 5,
Expand Down Expand Up @@ -199,7 +197,7 @@ c3 <-
xlab("Percentage of Referrals Achieved LDP Standard") +
ylab("")

ggsave(get_pub_figures_path(type = "c3"),
ggsave(get_pub_figures_path(type = "c3", test_output = test_output),
plot = c3,
height = 9,
width = 6,
Expand Down Expand Up @@ -257,7 +255,7 @@ c4 <-
ylab(str_wrap("Percentage of total referrals", width = 10))

# Save chart to output folder
ggsave(get_pub_figures_path(type = "c4"),
ggsave(get_pub_figures_path(type = "c4", test_output = test_output),
plot = c4,
width = 6.8,
height = 3.5,
Expand Down Expand Up @@ -327,7 +325,7 @@ c5 <-
ylab(str_wrap("Percentage of Referrals Achieved LDP Standard", width = 10))

# Save chart to output folder
ggsave(get_pub_figures_path(type = "c5"),
ggsave(get_pub_figures_path(type = "c5", test_output = test_output),
plot = c5,
width = 6.8,
height = 3.5,
Expand Down Expand Up @@ -383,7 +381,7 @@ c6 <-
ylab(str_wrap("Percentage of total referrals", width = 10))

# Save chart to output folder
ggsave(get_pub_figures_path(type = "c6"),
ggsave(get_pub_figures_path(type = "c6", test_output = test_output),
plot = c6,
width = 6.8,
height = 3.5,
Expand Down Expand Up @@ -445,7 +443,7 @@ c7 <-
ylab(str_wrap("Percentage of Referrals Achieved LDP Standard", width = 10))

# Save chart to output folder
ggsave(get_pub_figures_path(type = "c7"),
ggsave(get_pub_figures_path(type = "c7", test_output = test_output),
plot = c7,
width = 6.8,
height = 3.5,
Expand Down
4 changes: 2 additions & 2 deletions code/publication/03-knit-markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ source(here::here("code", "publication", "00_setup-pub-environment.R"))

render(
input = here("publication", "markdown", "summary.Rmd"),
output_file = get_pub_output_path(output_name = "pub_summary")
output_file = get_pub_output_path(output_name = "pub_summary", test_output = test_output)
)

### 2 - load environment file and load functions then knit REPORT ----
Expand All @@ -28,7 +28,7 @@ source(here::here("code", "publication", "00_setup-pub-environment.R"))

rmarkdown::render(
input = here("publication", "markdown", "report.Rmd"),
output_file = get_pub_output_path(output_name = "pub_report")
output_file = get_pub_output_path(output_name = "pub_report", test_output = test_output)
)

### END OF SCRIPT ###
4 changes: 2 additions & 2 deletions code/publication/04_create-excel-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source(here::here("code", "publication", "00_setup-pub-environment.R"))

### 2 - Load data ----

pds <- read_rds(get_pub_data_path())
pds <- read_rds(get_pub_data_path(test_output = test_output))

expected <- read_csv(get_exp_diagnoses_path()) %>%
select(-health_board)
Expand Down Expand Up @@ -195,7 +195,7 @@ writeData(wb,
sheetVisibility(wb)[10:11] <- "hidden"

saveWorkbook(wb,
get_pub_output_path(output_name = "excel_tables"),
get_pub_output_path(output_name = "excel_tables", test_output = test_output),
overwrite = TRUE)


Expand Down
4 changes: 2 additions & 2 deletions code/publication/05_create-discovery-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source(here::here("code", "publication", "00_setup-pub-environment.R"))

### 2 - Load data ----

pds <- read_rds(get_pub_data_path())
pds <- read_rds(get_pub_data_path(test_output = test_output))


### 3 - Restructure data ----
Expand Down Expand Up @@ -53,7 +53,7 @@ discovery <-

write_csv(
discovery,
get_pub_output_path(output_name = "discovery_data"))
get_pub_output_path(output_name = "discovery_data", test_output = test_output))


### END OF SCRIPT ###
4 changes: 2 additions & 2 deletions publication/markdown/report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ format_perc <- function(x, dp = 1){
# LDP Dataset
pds <-
read_rds(get_pub_data_path()) %>%
read_rds(get_pub_data_path(test_output = test_output)) %>%
filter(ijb != "Unknown" & referrals > 0)
# Expected Diagnoses (Incidence)
Expand All @@ -41,7 +41,7 @@ exp <- read_csv(get_exp_diagnoses_path()) %>%
# Error rates
err <-
read_rds(get_mi_data_path(type = "error_data", ext = "rds")) %>%
read_rds(get_mi_data_path(type = "error_data", ext = "rds", test_output = test_output)) %>%
filter(health_board == "Scotland" & fy %in% fy_in_pub) %>%
mutate(perc = format_perc(total_errors / records * 100)
) %>%
Expand Down

0 comments on commit 0315a54

Please sign in to comment.