Skip to content

Instantly share code, notes, and snippets.

View thebioengineer's full-sized avatar
🎯
Focused

Ellis Hughes thebioengineer

🎯
Focused
View GitHub Profile
@thebioengineer
thebioengineer / delayed_evaluation_in_pipes.R
Last active May 23, 2019 19:42
Testing delayed evaluation in pipes
`%>>>%`<-function(lhs,rhs){
parent <- parent.frame()
env <- new.env(parent = parent)
chain_parts <- magrittr:::split_chain(match.call(), env = env)
eval(as.call(call("%>%",call("%>%",chain_parts$lhs$lhs,substitute(play)),chain_parts$lhs$rhs)))
}
play<-function(lhs){
delayedexpr<-as.list(attr(lhs,"delayedeval"))
delayedFunc<-delayedexpr[[length(delayedexpr)]]
@thebioengineer
thebioengineer / reinforce_snake.R
Created July 10, 2019 05:08
An implementation of the game "Snake" in an R refclass
snake<-setRefClass("snake",
fields=list(
# System variables
body="matrix",
food = "numeric",
direction='character',
length="numeric",
dead="logical",
#game info
---
title: "NFL Game Crosstalk"
author: "Ellis Hughes"
date: "12/18/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
@thebioengineer
thebioengineer / Print_Limits.R
Last active April 14, 2020 18:53
simple overriding print.default method to prevent accidentally printing large objects
# what object size should be prevented from being printed. Defaults to ~ 30mb, which is not very large
options("print_protect.print_size_bytes" = "30000")
# This method ONLY applies to functions sent to print.default (ie. matrix & vectors)
print.default <- function(x, ...) {
x_bytes <- as.numeric(utils::object.size(x))
answer <- "NA"
if (interactive() &
x_bytes >
@thebioengineer
thebioengineer / notebook_paged_table_bug.Rmd
Created April 29, 2020 04:49
Identifying potential issue with inline printing in tables
---
title: "R Notebook"
output: html_notebook
editor_options:
chunk_output_type: inline
---
```{r setup}
library(tibble)
@thebioengineer
thebioengineer / popout_notebook_executing_inconsistency.Rmd
Last active April 29, 2020 04:57
Strange RStudio Notebooks behavior
---
output: html_document
editor_options:
chunk_output_type: inline
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
# remotes::install_github("thebioengineer/colortable")
@thebioengineer
thebioengineer / tt_record and tt_playback
Created July 28, 2020 06:33
provide tools for recording and then playing back tidytuesday plot generation! (Assumes you are using ggplot)
tt_recording_env <- new.env()
tt_record <- function(dir = tempdir(),
device = c("png", "jpeg", "bmp", "tiff", "emf", "svg", "eps"),
scale = 1,
width = NA,
height = NA,
units = c("in", "cm", "mm"),
@thebioengineer
thebioengineer / fun_with_camcorder.R
Created November 1, 2021 00:37
Create a sample gif with camcorder
require(ggplot2)
library(ggimage)
if(!require(camcorder)){
remotes::install_github("thebioengineer/camcorder")
library(camcorder)
}
gg_record()