🏳️🌈
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# colors via https://twitter.com/dataandme/status/1531946768270860288 | |
pride <- c( | |
red = '#E50000', | |
orange = '#FF8D00', | |
yellow = '#FFEE00', | |
green = '#028121', | |
blue = '#004CFF', | |
purple = '#760088', | |
black = '#000000', | |
brown = '#613915', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(dplyr) | |
# make starting vector | |
A = LETTERS[5:1] | |
# pre-allocate matrix to store steps | |
n = length(A) | |
steps <- matrix(nrow = (n*n)+1, | |
ncol = 2 + n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find all packages used in this project ---- | |
# include this file to test odd library formations: | |
library( 'dplyr' ) # for pipes | |
library("purrr") # for iteration | |
library( stringr ) # for text extraction | |
# find files that might have library() or pkg::func() notation | |
# EDIT FOR YOUR PROJECT | |
qmd_files <- list.files(pattern = "\\.qmd$") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Table printing demo" | |
author: "Lisa DeBruine" | |
toc: true | |
toc_float: true | |
--- | |
## Code | |
These functions should override `knitr::knit_print()` for data frames, but wasn't working at all until I learned in [the knit_print vignette](https://cran.r-project.org/web/packages/knitr/vignettes/knit_print.html) that you have to use `registerS3method()`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inpired by https://github.com/IcaroBernardes/30DayChartChallenge/blob/master/2022/day10/day10.R | |
library(ggplot2) | |
library(dplyr) | |
library(sf) | |
library(ggforce) # for voroni tiles | |
seed <- 8675309 | |
n_pts <- 150 ### Number of points to try to put inside the window | |
palette <- c( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replace figure captions like: | |
# | |
# ```{r myfigure, fig.cap = "This is my figure."} | |
# | |
# with text captions like this: | |
# | |
# (ref:myfigurelab) This is my figure. | |
# | |
# ```{r myfigure, fig.cap = "(ref:myfigurelab)"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Crosstabs with margins | |
#' | |
#' @param data Data frame or tibble | |
#' @param row Column name (string or index) for rows | |
#' @param col Column name (string or index) for columns | |
#' @param margin_func Margin function (e.g., sum, mean, median) | |
#' @param margin_label Label for margin column and row | |
#' @param col_prefix Prefix for columns (defaults to col name), set to FALSE to omit; If return == "kable", this is used for the grouping header | |
#' @param return Return a tibble or formatted kableExtra table | |
#' @param ... Arguments to pass to kableExtra::kable() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(faux) | |
library(afex) | |
f <- function(r, reported) { | |
# simulate data for 3-level within design (change for your design) | |
dat <- faux::sim_design( | |
# you can add these parameters to f() arguments | |
# if you need to check varying analyses | |
n = 100, within = 3, | |
mu = c(100, 105, 110), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(tidyr) | |
library(readxl) | |
library(lubridate) | |
# deal with multi-line headers | |
data_head <- readxl::read_excel("Doodle.xls", | |
skip = 3, n_max = 3, | |
col_names = FALSE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(faux) | |
library(tidyverse) | |
library(lme4) | |
# simulate nested data with 12 subjects tested at 6 time points with 100 observations per time point | |
dat <- add_random(ID = 12) %>% | |
add_random(Time = 1:6) %>% | |
add_within(rep = 1:100) %>% | |
add_ranef(.by = "ID", id_int = 2, id_slope = 1) %>% | |
add_ranef(.by = "Time", time_int = 1) %>% |
NewerOlder