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 / write-qr.R
Last active October 24, 2023 10:24
Write a QR code to disk with {qrcode} and `png()`
png(
"~/Desktop/qr_test.png",
width = 5,
height = 5,
units = "cm",
res = 1200
)
qrcode::qr_code("https://www.matt-dray.com") |> plot()
@matt-dray
matt-dray / long-base-fn-names.R
Last active May 5, 2023 09:01
How long are the longest function names in base R?
# This became a blogpost here: https://www.rostrum.blog/2021/11/27/long-fns/
base_names <- sessionInfo()$basePkgs
base_names
base_fns <- lapply(base_names, \(x) ls(getNamespace(x), all.names=TRUE)) |>
setNames(base_names) |>
lapply(\(object) as.data.frame(object)) |>
(\(x) do.call(rbind, x))() # the balls ()()
@matt-dray
matt-dray / check-rproj-dupes.R
Last active August 10, 2022 21:03
R function to check for open RStudio Projects that have the same name (macOS only for now). Provides a warning in the console on start-up and (optionally) uses speech to text to tell you which ones are duplicated. You could put this in your .Rprofile so it runs on startup.
# See blogpost for details:
# https://www.rostrum.blog/2022/07/08/rproj-dupes/
check_rproj_dupes <- function(speak = FALSE) {
os <- .Platform$OS.type
if (os == "unix") {
ps_out <- system("ps -e", intern = TRUE)
@matt-dray
matt-dray / explore-isodungeon-eventloop-enemy.R
Last active June 23, 2022 17:01
Build a dungeon from isometric cubes with {isocubes} and {r.oguelike} and explore it interactively thanks to {eventloop} – also you're followed by a pathfinding enemy (yellow)
# Using {isocubes}, {eventloop} and {r.oguelike} to move a cube around an
# isometric 'dungeon', featuring an enemy that chases you down
# Matt Dray, June 2022
# Builds on an earlier Gist that doesn't include an enemy:
# https://gist.github.com/matt-dray/dcbd5cd2f4bdc471921e5c741a1233c0
# Move actors -------------------------------------------------------------
@matt-dray
matt-dray / explore-isodungeon-eventloop.R
Last active June 24, 2022 21:38
Build a dungeon from isometric cubes with {isocubes} and {r.oguelike} and explore it interactively thanks to {eventloop}
# Using {isocubes}, {eventloop} and {r.oguelike} to move a cube around an
# isometric 'dungeon', featuring an enemy that chases you down
# Matt Dray, June 2022
# Builds on an earlier Gist that doesn't include an enemy:
# https://gist.github.com/matt-dray/dcbd5cd2f4bdc471921e5c741a1233c0
# Move actors -------------------------------------------------------------
@matt-dray
matt-dray / explore-isodungeon.R
Last active August 8, 2022 15:50
Build a dungeon from {isocubes}/{oblicubes} and {r.oguelike} and explore it
# Create a procedural dungeon with {r.oguelike}, either in isometric
# with {isocubes} or oblique with {oblicubes}
# Matt Dray, August 2022
# See blogpost:
# https://www.rostrum.blog/2022/06/28/isometric-dungeon/
# Prompt for WASD keys (i.e. up, left, down, right)
accept_keypress <- function() {
@matt-dray
matt-dray / testing-isocubes.R
Last active June 21, 2022 20:41
Testing out {isocubes} with a Link sprite, procedural dungeon and the logo for rostrum.blog
# Testing the {isocube} package by coolbutuseless (mikefc)
# Package on GitHub: https://github.com/coolbutuseless/isocubes
# Matt Dray, June 2022
# Attach generally-needed packages
library(grid) # installed with base R
library(purrr) # install from CRAN
library(isocubes) # remotes::install_github("coolbutuseless/isocubes")
@matt-dray
matt-dray / simple-labels.R
Created June 17, 2022 08:33
Simple demo of variable and value labels in R
library(tidyverse)
library(haven)
library(labelled)
x <- tibble(
A01 = c(1, 2, 1),
A02 = c(2, 3, 1)
)
var_label(x) <-
@matt-dray
matt-dray / point_down.R
Last active June 7, 2022 01:20
A function to execute 'down assignment' in R, which is something I've just made up and is absolutely not practical. You're welcome.
demo_script <- "
1
|
v
x
2
|
v
y
@matt-dray
matt-dray / laundry.png
Created June 2, 2022 12:18
Testing out R's new plotting symbols
library(ggplot2)
library(ggsvg)
td_1_url <- "https://upload.wikimedia.org/wikipedia/commons/d/d0/Trommeltrocknen.svg"
td_2_url <- "https://upload.wikimedia.org/wikipedia/commons/0/0c/Trommeltrocknen_1.svg"
td_3_url <- "https://upload.wikimedia.org/wikipedia/commons/1/14/Trommeltrocknen_2.svg"
td_4_url <- "https://upload.wikimedia.org/wikipedia/commons/3/38/Nicht_trommeltrocknen.svg"
td_1 <- paste(readLines(td_1_url), collapse = "\n")
td_2 <- paste(readLines(td_2_url), collapse = "\n")