Skip to content

Commit

Permalink
Add xlsx from url function
Browse files Browse the repository at this point in the history
  • Loading branch information
viv3ckj committed Jan 6, 2025
1 parent 12dd6b2 commit 306004c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/functions/eps_erd_prescribing_data.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
library(tidyverse)
library(janitor)
library(here)
library(httr)

# Function to download and read the xlsx files
read_xlsx_from_url <- function(url_list, sheet = NULL, skip = NULL, ...) {
temp_file <- tempfile(fileext = ".xlsx")
GET(
url_list,
write_disk(temp_file, overwrite = TRUE)
)
readxl::read_xlsx(
temp_file,
col_names = TRUE,
.name_repair = janitor::make_clean_names,
sheet = sheet,
skip = skip,
...
)
}

df <- read_xlsx_from_url(
"https://github.com/user-attachments/files/17774058/EPS.and.eRD.Prescribing.Dashboard.July.2024.xlsx",
skip = 2,
sheet = "Historical Data"
)

df_filtered <- df %>%
select(month, region_code, practice_code, eps_items, erd_items) %>%
filter(month %in% c(202402, 202403, 202404, 202405, 202406, 202407)) %>%
mutate(month = ym(month))

df_filtered |> write_csv(
here("lib", "validation", "data", "eps_erd_prescribing_2024-02-01_to_2024-07-01.csv")
)

0 comments on commit 306004c

Please sign in to comment.