Skip to content

Instantly share code, notes, and snippets.

View erikerhardt's full-sized avatar

Erik Erhardt erikerhardt

View GitHub Profile
https://cran.r-project.org/web/packages/dplyr/vignettes/programming.html
# let var_xs and var_name_y be character strings with variable names, then:
geom_point(
data = dat_cont
, aes(x = !!rlang::sym(var_xs), y = !!rlang::sym(var_name_y))
, alpha = geom_point_alpha
)
@erikerhardt
erikerhardt / quarto_table_figure_captions_template
Last active July 24, 2023 16:21
quarto_table_figure_captions_template
# https://quarto.org/docs/authoring/tables.html
```{r}
#| label: tbl-example
#| tbl-cap: "Example caption can
#| continue on the next line"
#| tbl-subcap:
#| - "Cars"
#| - "Pressure"
#| layout-ncol: 2
#| echo: fenced
@erikerhardt
erikerhardt / quarto extensions
Created August 1, 2023 14:28
quarto extensions
quarto titlepages v3.0: Demo of customizing a title page
https://youtu.be/SZ0WJMHGDps
@erikerhardt
erikerhardt / Summary_tables_example.qmd
Last active September 9, 2023 15:57
Tables using gtsummary: Table 1 (demographics), regression, contingency table, etc.
---
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 December 15, 2023 01:40
A qmd quarto template document, simple
---
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 December 15, 2023 01:40
A qmd quarto template document, full
---
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
@erikerhardt
erikerhardt / erik_qmd_template_presentation_pptx.qmd
Created December 15, 2023 01:41
erik_qmd_template_presentation_pptx.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
date-format: "MM/DD/YYYY \\ hh:mm:ss A ZZ"
google-scholar: true
author-title: Author
affiliation-title: Affiliation
# path
path_original <- setwd(path)
on.exit(setwd(path_original), add = TRUE)
## Example error capture
# First check if effect is involved in interactions
check_message <-
e_message_capture(
[^\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.
# Replace unicode in all variables
dat_all <-
dat_all |>
dplyr::mutate(
dplyr::across(
@erikerhardt
erikerhardt / f_ggplot_grid_workflow.R
Last active March 12, 2024 15:35
R ggplot plot and grid.arrange workflow
## Erik's workflow template for plots in R ggplot2
library(erikmisc) # https://github.com/erikerhardt/erikmisc/
# https://patchwork.data-imaginist.com/articles/guides/layout.html
# When lazy evaluation (nonstandard evaluation NSE) is an issue with plots into a list
# force evaluation by running cowplot (have not found a better way using force() or eval() or tidy_eval())
# p_list[[ i_plot ]] <- p |> cowplot::plot_grid()