Initial Setup

knitr::opts_chunk$set(echo = TRUE)

set.seed({{format(Sys.Date(), format = "%Y%m%d")}})

Raw Data Import

library(gtsummary); library(tidyverse)

# setting and gtsummary theme
theme_gtsummary_compact()

# example code for importing excel file
df_raw_data <-
  readxl::read_excel(
    path = here::here("secure_data", "Raw Data from PI.xlsx")
  ) %>%
  janitor::clean_names(case = "all_caps") %>% # uppercase col names
  mutate(across(where(lubridate::is.POSIXt), lubridate::as_date)) # use lubridates

Create Master Analytic Data Set


Check Variables


Save Analytic Data

# applying variable labels, and dropping raw variables
df_main <- df_main %>%
  set_derived_variables(path = here::here("scripts/derived_variables.xlsx"))

# overview of master analytic dataset
skimr::skim(df_main)

# saving master analytic data set
saveRDS(
  object = df_main,
  file = here::here("secure_data", "df_main.Rds")
)


Try the starter package in your browser

Any scripts or data that you put into this service are public.

starter documentation built on Oct. 15, 2024, 5:06 p.m.