Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik Erhardt erikerhardt

View GitHub Profile
View knitr_helpers.R
# from inline to yaml chunk options
knitr::convert_chunk_header()
# Verbatim engine for instruction
# https://bookdown.org/yihui/rmarkdown-cookbook/verbatim-code-chunks.html
@erikerhardt
erikerhardt / read_fn_current.R
Created Sep 5, 2022
Read current (most recent) files in folder
View read_fn_current.R
## Read current files
# Assumed file naming structure is Filename_YYYYMMDD.csv
# list of all files
fn_list_data_raw <- dir("data/")
# filenames to match
fn_dat_list_in <-
c(
@erikerhardt
erikerhardt / Summary_tables_example.qmd
Last active Aug 22, 2022
Tables using gtsummary: Table 1 (demographics), regression, contingency table, etc.
View Summary_tables_example.qmd
---
title: Tables using `gtsummary`
subtitle: Example workflow for Table 1 (demographics), regression, contingency table, etc.
author: Erik Erhardt
date: last-modified # today, now, last-modified
date-format: long # full, long, medium, short, iso, https://quarto.org/docs/reference/dates.html
format:
html:
theme: litera
highlight-style: atom-one
@erikerhardt
erikerhardt / erik_qmd_template_simple.qmd
Last active Sep 6, 2022
A qmd quarto template document, simple
View erik_qmd_template_simple.qmd
---
title: Title
subtitle: Subtitle
author: Erik Erhardt
date: last-modified # today, now, last-modified
date-format: long # full, long, medium, short, iso, https://quarto.org/docs/reference/dates.html
format:
html:
theme: litera
highlight-style: atom-one
@erikerhardt
erikerhardt / erik_qmd_template.qmd
Last active Sep 6, 2022
A qmd quarto template document, full
View erik_qmd_template.qmd
---
title: Title
subtitle: Subtitle
description: |
A qmd quarto template document.
abstract: |
Document abstract may be somewhat long.
author:
- name: Erik Erhardt
url: https://StatAcumen.com/about
View Error capture and do
# Example error capture
# First check if effect is involved in interactions
check_message <-
e_message_capture(
emmeans::emmeans(
object = fit
, specs = var_xs
)
)(1)
@erikerhardt
erikerhardt / convert_character_to_factor.R
Last active Sep 16, 2022
Convert all character to factor
View convert_character_to_factor.R
iris_e <- iris
str(iris_e)
# from factor to character
iris_e <- iris_e %>% mutate(across(where(is.factor), as.character))
str(iris_e)
# from character to factor
iris_e <- iris_e %>% mutate(across(where(is.character), as.factor))
str(iris_e)
View e_table1_summaries
```{r, results='asis'}
# list of column variables for table
list_var_col_names <- "Group"
list_var_col_labels <- "Group"
# list of row variables for table
list_var_row_names <- c(Var[["list"]][["var_resp"]] , Var[["list"]][["var_covar"]] )
list_var_row_labels <- c(Var[["label"]][["var_resp"]], Var[["label"]][["var_covar"]])
fn_root <- "./out/tab1_vars_dx_demo"
View find_unicode.R
[^\x00-\x7F]
To fix this, you have to find the Unicode and replace it with it’s ASCII equivalent. To do this: Ctrl-F to find, search for “[^\x00-\x7F]” (without quotes), select “Regex” for regular expressions, and find the “Next” one.