Skip to content

Instantly share code, notes, and snippets.

@MrFlick
MrFlick / find_name_index.R
Created June 8, 2023 14:17
Find index of name in nested list
find_name_index <- function(haystack, needle, idx=c()) {
if (hasName(haystack, needle)) {
c(idx, which(names(haystack)==needle))
} else if (is.list(haystack)) {
for (i in seq_along(haystack)) {
obj <- haystack[[i]]
ret <- Recall(obj, needle, c(idx,i))
if (!is.null(ret)) return(ret)
}
} else {
@MrFlick
MrFlick / try-it-tracker.lua
Created March 24, 2022 04:52
OBS On Screen Timer
obs = obslua
source_name = ""
total_seconds = 0
timer_state = 0
time_delta = 30
cur_seconds = 0
last_text = ""
stop_text = ""
activated = false
@MrFlick
MrFlick / pheweb.R
Created March 23, 2022 21:03
Pheweb variant plot in ggplot2
library(httr)
library(jsonlite)
library(ggplot2)
library(ggrepel)
variant <- "4-74853287-G-A"
getVariantData <- function(variant) {
raw <- GET(paste0("http://pheweb.sph.umich.edu/FinMetSeq/variant/", variant))
html <- content(raw, as="text")
@MrFlick
MrFlick / world_map.R
Last active July 6, 2021 01:27
Plotting the world (gapminder data)
library(gapminder)
library(dplyr)
library(ggplot2)
library(ggthemes)
mapdata <- map_data("world") %>%
mutate(region = recode(region,
USA="United States",
UK="United Kingdom"))
@MrFlick
MrFlick / alpha.csv
Last active June 21, 2019 21:22
Plotting Sample Data
x y
32.3311102266 61.411101248
53.4214628807 26.1868803879
63.92020226 30.8321939163
70.2895057187 82.5336485877
34.1188302357 45.7345513203
67.6707164012 37.110947969
53.2591294055 97.4757710964
63.5149808671 25.1000785788
67.9805388133 80.9571652197
@MrFlick
MrFlick / panel.barchart.alpha.R
Last active June 13, 2019 20:00
Update lattice bwplot to use alpha
panel.barchart.alpha <- function (x, y, box.ratio = 1, box.width = box.ratio/(1 + box.ratio),
horizontal = TRUE, origin = NULL, reference = TRUE, stack = FALSE,
groups = NULL, col = if (is.null(groups)) plot.polygon$col else superpose.polygon$col,
border = if (is.null(groups)) plot.polygon$border else superpose.polygon$border,
lty = if (is.null(groups)) plot.polygon$lty else superpose.polygon$lty,
lwd = if (is.null(groups)) plot.polygon$lwd else superpose.polygon$lwd,
alpha = if (is.null(groups)) plot.polygon$alpha else superpose.polygon$alpha,
..., identifier = "barchart")
{
plot.polygon <- trellis.par.get("plot.polygon")
@MrFlick
MrFlick / find_vars.R
Created May 6, 2019 14:26
list variables in quosure
# List a variable names (that are not functions) in
# a quosure
# ideas taken from https://adv-r.hadley.nz/expressions.html
find_vars <- function(x) {
extr <- function(x)
if (is.symbol(x)) {
as.character(x)
} else if (is.pairlist(x)) {
purrr::flatten_chr(purrr::map(as.list(x), find_vars))
@MrFlick
MrFlick / powerpoint.vb
Created August 31, 2018 22:19
Create animation from one shape to another (before/after)
Sub animate_to()
Dim oslide As slide
Set oslide = ActiveWindow.View.slide
Dim oeff As effect
Dim oani As AnimationBehavior
Dim pHeight As Single
Dim pWidth As Single
With ActivePresentation.PageSetup
pHeight = .SlideHeight
@MrFlick
MrFlick / sparkler.R
Created July 13, 2017 19:28
Point selection with R Shiny
library(shiny)
library(tidyverse)
mydata <- tibble::rowid_to_column(mpg)
ui <- fluidPage(
titlePanel("Sparkler"),
plotOutput("facet1", brush="facet1_brush"),
textOutput("numsel"),
actionButton("done", "Done")
---
title: "Dplyr Introduction"
author: "Matthew Flickinger"
date: "July 12, 2017"
output:
pdf_document: default
html_document: default
---
```{r setup, include=FALSE}