Skip to content

Instantly share code, notes, and snippets.

View matt-dray's full-sized avatar
®️

Matt Dray matt-dray

®️
View GitHub Profile
@matt-dray
matt-dray / googleVis_test.Rmd
Last active April 23, 2019 11:15
Display a {googleVis} graphic in R Markdown
---
title: "googleVis test"
author: "Matt Dray"
date: "23/04/2019"
output: html_document
---
Set up example dataframe from [the {googleVis} examples](https://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html) CRAN vignette.
```{r}
@matt-dray
matt-dray / brickr_soccer_kit.R
Created May 30, 2019 20:56
A function to create a soccer player using {brickr}
# Packages
library(brickr)
library(rayshader)
library(tibble)
# Function that takes colours for different parts of the player model.
# Colour codes as per brickr::lego_colors
# Output is a bricks_from_table() list object
# Output should be fed to display_bricks()
@matt-dray
matt-dray / brickr-soccer-colours.R
Created June 1, 2019 15:40
Colour combinations for certain soccer teams to be used to create 3D {brickr} models
# Create a soccer player using {brickr}
# This file specifies some colour combinations for certain teams
# Blog post: https://www.rostrum.blog/2019/05/31/brickr-soccer/
# You need to load some packages
# library(brickr)
# library(dray) # from remotes::install_github("matt-dray/dray")
# After creating a colour specification, pass it to
# bricks_from_table() %>% display_bricks() to render it
@matt-dray
matt-dray / get_expansion.R
Last active September 5, 2019 14:41
Expand c(1:3) and c(1, 2, 3) to c(1, 2, 2, 3, 3, 3) and c(1, 1, 2, 1, 2, 3) ready for purrr::map() functions in R
# This isn't optimal and there's probably
# a function that does all this already
# Packages
library(dplyr)
library(purrr)
library(tibble)
# Write function
get_expansion <- function(x, y) {
@matt-dray
matt-dray / gitalias.txt
Created October 9, 2019 14:34
Git aliases
alias.hist=log --decorate --oneline --graph --all
@matt-dray
matt-dray / allequal-tibble-dataframe.R
Last active October 19, 2019 00:02
Testing comparisons between data.frame and tibble objects with all.equal()
# all.equal() behaves differently when presented with objects of class
# data.frame versus those with tibble class. This is important for
# trying to rewrite the {tidyr} episode of Software Carpentry's
# R for Reproducible Scientific Analysis lesson to include the new
# pivot_wider() and pivot_longer() columns instead of spread() and
# gather(), which have been superseded.
# Seems to be a noted problem:
# https://github.com/tidyverse/tibble/issues/287
@matt-dray
matt-dray / DATADIR.sh
Created October 21, 2019 11:04
DATADIR location
cd /Users/matthewdray/.bash_profile
@matt-dray
matt-dray / regex-example.py
Last active October 21, 2019 12:24
Basic re module usage to find text strings
# Import re for working with regular expressions
import re
# Provide some text to search
# 'Hipster ipsum' via https://hipsum.co/
text = "Lorem ipsum dolor amet selfies williamsburg tattooed ethical wolf cloud bread. Cronut marfa heirloom pour-over. Jean shorts aesthetic before they sold out, yr subway tile kale chips occupy. Banjo lomo af, meditation roof party cronut vape glossier."
# Search for a specific phrase
# Returns a 'match' object
# More info here: https://www.w3schools.com/python/python_regex.asp#matchobject
@matt-dray
matt-dray / expand-details-date-sessioninfo.Rmd
Last active October 22, 2019 08:07
Handy snippets for rostrum.blog
---
<details><summary>Session info</summary>
```{r sessioninfo, echo=FALSE}
paste("Last updated", Sys.Date())
xfun::session_info()
```
</details>
@matt-dray
matt-dray / screenshot-gif-rstudio.R
Created December 23, 2019 12:08
Use {magick} to read 'before' and 'after' images to a gif
library(magick)
before <- image_read("~/Desktop/before.png")
before <- image_crop(before, "815x300-80-200")
after <- image_crop(image_read("~/Desktop/after.png"))
after <- image_crop(after, "815x300-80-200")
# To morph
# frames <- image_morph(c(before, after, before), frames = 20)