Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary table create r table format #116

Open
wants to merge 13 commits into
base: development
Choose a base branch
from

Conversation

khansh01
Copy link

@khansh01 khansh01 commented Oct 8, 2024

Created new R Markdown for flextable summary table

@Moohan Moohan changed the base branch from main to development October 8, 2024 14:10
Copy link
Member

@Moohan Moohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

I've made lots of suggestions, but nothing major 👍

I did notice a mix of pipes - I think |> is preferred now, so if unless there's something I missed where you're using a special ability of %>% could you swap them out to make it consistent please?

title: ''
output:
word_document:
reference_docx: "//conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/Summary Table/ST_ref_doc.docx"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reference_docx: "//conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/Summary Table/ST_ref_doc.docx"
reference_docx: "/conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/Summary Table/ST_ref_doc.docx"

word_document:
reference_docx: "//conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/Summary Table/ST_ref_doc.docx"
---
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this is a typo?

Suggested change
;

# LOCALITY <- "Whalsay and Skerries"
# LOCALITY <- "Inverclyde East"

# setwd("~/list-localities-profiles/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't ever need this?

Suggested change
# setwd("~/list-localities-profiles/")

Comment on lines 21 to 41
## Project file path
lp_path <- "/conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/"

# Source in global functions/themes script
source("./Master RMarkdown Document & Render Code/Global Script.R")

# # demographics
source("./Demographics/1. Demographics - Population.R")
source("./Demographics/2. Demographics - SIMD.R")
#
# # housing
source("./Households/Households Code.R")
#
# # general health
source("./General Health/3. General Health Outputs.R")
#
# # lifestyle & risk factors
source("./Lifestyle & Risk Factors/2. Lifestyle & Risk Factors Outputs.R")
#
# # unscheduled care
source("./Unscheduled Care/2. Unscheduled Care outputs.R")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these will need to be removed or commented out. I guess they were/are used for testing but we don't want them added uncommented?

Is sourcing all the scripts here the best way to test the summary table?

library(officer)
library(officedown)

# detach(package:tidylog, unload = TRUE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# detach(package:tidylog, unload = TRUE)

color(part = "header", color = "white") %>%
bg(part = "header", bg = "#3F3685") %>%
bg(j = 1:3, part = "body", bg = "grey90") |>
# width(j = 1, width = "22em") |>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# width(j = 1, width = "22em") |>

scot_values <- c(scot_alcohol_hosp, scot_alcohol_deaths, scot_drug_hosp, scot_bowel_screening)


lifestyle_values <-data.frame(indicators, datatype, time, loc_values, other_loc_values,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lifestyle_values <-data.frame(indicators, datatype, time, loc_values, other_loc_values,
lifestyle_values <- tibble(indicators, datatype, time, loc_values, other_loc_values,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another random observation (that I looked up) - tibble preserves all of the variable types whereas in old versions of r data.frame may convert strings into factors.

Comment on lines 330 to 348
UC_values <-data.frame(indicators, datatype, time, loc_values, other_loc_values,
hscp_values, scot_values)

colnames(UC_values) <- headings

UC_table <- flextable(UC_values) %>%
bold(part = "header") %>%
bold(j = 1, bold = TRUE, part = "body") %>%
fontsize(part = "header", size = 12) %>%
font(part = "body", fontname = "Arial") |>
font(part = "header", fontname = "Arial") |>
color(part = "header", color = "white") %>%
bg(part = "header", bg = "#3F3685") %>%
bg(j = 1:3, part = "body", bg = "grey90") |>
# width(j = 1, width = "22em") |>
border(border = fp_border(color = "white", width = 1), part = "body") |>
set_table_properties(layout = "autofit")

UC_table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double check that UC_values and/or UC_table isn't used elsewhere before applying this suggestion.

Suggested change
UC_values <-data.frame(indicators, datatype, time, loc_values, other_loc_values,
hscp_values, scot_values)
colnames(UC_values) <- headings
UC_table <- flextable(UC_values) %>%
bold(part = "header") %>%
bold(j = 1, bold = TRUE, part = "body") %>%
fontsize(part = "header", size = 12) %>%
font(part = "body", fontname = "Arial") |>
font(part = "header", fontname = "Arial") |>
color(part = "header", color = "white") %>%
bg(part = "header", bg = "#3F3685") %>%
bg(j = 1:3, part = "body", bg = "grey90") |>
# width(j = 1, width = "22em") |>
border(border = fp_border(color = "white", width = 1), part = "body") |>
set_table_properties(layout = "autofit")
UC_table
uc_values <- tibble(indicators, datatype, time, loc_values, other_loc_values,
hscp_values, scot_values)
colnames(uc_values) <- headings
UC_table <- flextable(uc_values) %>%
bold(part = "header") %>%
bold(j = 1, bold = TRUE, part = "body") %>%
fontsize(part = "header", size = 12) %>%
font(part = "body", fontname = "Arial") |>
font(part = "header", fontname = "Arial") |>
color(part = "header", color = "white") %>%
bg(part = "header", bg = "#3F3685") %>%
bg(j = 1:3, part = "body", bg = "grey90") |>
border(border = fp_border(color = "white", width = 1), part = "body") |>
set_table_properties(layout = "autofit")
uc_table

Comment on lines 375 to 396
UC_MH_values <-data.frame(indicators, datatype, time, loc_values, other_loc_values,
hscp_values, scot_values)

colnames(UC_MH_values) <- headings

UC_MH_table <- flextable(UC_MH_values) %>%
bold(part = "header") %>%
bold(j = 1, bold = TRUE, part = "body") %>%
fontsize(part = "header", size = 12) %>%
font(part = "body", fontname = "Arial") |>
font(part = "header", fontname = "Arial") |>
color(part = "header", color = "white") %>%
bg(part = "header", bg = "#3F3685") %>%
bg(j = 1:3, part = "body", bg = "grey90") |>
# width(j = 1, width = "22em") |>
border(border = fp_border(color = "white", width = 1), part = "body") |>
set_table_properties(layout = "autofit")

UC_MH_table



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UC_MH_values <-data.frame(indicators, datatype, time, loc_values, other_loc_values,
hscp_values, scot_values)
colnames(UC_MH_values) <- headings
UC_MH_table <- flextable(UC_MH_values) %>%
bold(part = "header") %>%
bold(j = 1, bold = TRUE, part = "body") %>%
fontsize(part = "header", size = 12) %>%
font(part = "body", fontname = "Arial") |>
font(part = "header", fontname = "Arial") |>
color(part = "header", color = "white") %>%
bg(part = "header", bg = "#3F3685") %>%
bg(j = 1:3, part = "body", bg = "grey90") |>
# width(j = 1, width = "22em") |>
border(border = fp_border(color = "white", width = 1), part = "body") |>
set_table_properties(layout = "autofit")
UC_MH_table
uc_mh_values <- tibble(indicators, datatype, time, loc_values, other_loc_values,
hscp_values, scot_values)
colnames(uc_mh_values) <- headings
uc_mh_table <- flextable(uc_mh_values) %>%
bold(part = "header") %>%
bold(j = 1, bold = TRUE, part = "body") %>%
fontsize(part = "header", size = 12) %>%
font(part = "body", fontname = "Arial") |>
font(part = "header", fontname = "Arial") |>
color(part = "header", color = "white") %>%
bg(part = "header", bg = "#3F3685") %>%
bg(j = 1:3, part = "body", bg = "grey90") |>
border(border = fp_border(color = "white", width = 1), part = "body") |>
set_table_properties(layout = "autofit")
uc_mh_table

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this file should have been committed. We can add HTML files to the .gitignore so git ignores them in the future but can you delete this please?

@@ -34,15 +34,15 @@ library(reshape2)
# LOCALITY <- "Ayr North and Former Coalfield Communities"
# LOCALITY <- "Whalsay and Skerries"
# LOCALITY <- "North Perthshire"

#LOCALITY <- "Inverclyde East"
# Set date limit for financial year
# Unless we're in Q4 use the previous FY as the max
max_fy <- ifelse(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether I've commented on this before hmmmmmm. Would it be better having the max_fy as a function in Global?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Summary table - Actual table in the final output
3 participants