Skip to content

Instantly share code, notes, and snippets.

View brfitzpatrick's full-sized avatar
🐜

Ben R. Fitzpatrick brfitzpatrick

🐜
View GitHub Profile
@brfitzpatrick
brfitzpatrick / SLURM_foreach.md
Last active February 7, 2024 18:03
minimal example of using `foreach` parallelism on a clusters managed by SLURM

Job script:

#!/bin/bash

#SBATCH --job-name=rfee
#SBATCH --workdir=/home/user.name/rfee/
#SBATCH --output=r_foreach_example_console_output.txt
#SBATCH --mem-per-cpu=100 # specify RAM per CPU here in Mb
#SBATCH --time=0:02:00
@brfitzpatrick
brfitzpatrick / R2PBS.md
Last active July 26, 2020 07:07
How to submit R code to a Portable Batch System (PBS) managed HPC resource (e.g. QUT's High Performance Computing Facility `Lyra').

How to submit R code to a Portable Batch System (PBS) managed High Performance Computing (HPC) Facility (e.g. QUT's HPC Facility 'Lyra').

You will need:

  1. An account with the relevant HPC facility (QUT staff and HDR students can request access to the QUT facility here),
  2. the R Script (.R file) you want to run,
  3. a Job Script (.sub file) that tells Lyra how to run your R script and,
  4. a file containing any data your R Script needs to run.

Note: These instructions work on a system running Debian (GNU + Linux) with the Gnome Desktop Environment.

@brfitzpatrick
brfitzpatrick / .emacs
Last active July 22, 2019 09:15
emacs25 ~/.emacs
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes (quote (manoj-dark)))
'(package-selected-packages (quote (polymode)))
'(show-paren-mode t))
(electric-indent-mode -1)
@brfitzpatrick
brfitzpatrick / list.files( ) + assign( )
Created April 22, 2016 21:39
Read all files in a directory into R
# general demo
setwd('~/Documents/directory_of_csv_files/')
# create a collection of .csv files names following some system
X <- expand.grid(LETTERS,1:10)
for(i in 1:nrow(X)){
Data.i <- data.frame(matrix(data = rnorm(1000), nrow = 10))
@brfitzpatrick
brfitzpatrick / leaRn.md
Last active January 23, 2019 14:50
A short list of online resources for self directed learning of the R Language and Environment for Statistical Computing and Graphics

Online Courses

Books:

  • R for Data Science by Hadley Wickham & Garrett Grolemund (an actual book that you can also read for free online)

Reference Cards/Cheat Sheets

input.seq <- 1:10
for(i in 1:length(input.seq)){
file.con <-file(paste0('script', input.seq[i], '.R'))
writeLines(
text = c("source('my.fun.R')",
paste0('result', i, ' <- my.fun(x = ', i, ", y = 'character input')"),
paste0("save(list = 'result", i, "', file = 'result", i, ".RData')")
),
con = file.con
@brfitzpatrick
brfitzpatrick / vis_nb_wghts_sf.R
Created December 20, 2018 23:14
Visualising Neighbourhood Weights
library(sp)
library(spdep)
library(tidyverse)
library(sf)
data(meuse)
nb.boundary.radius <- 750
nb.obj <- dnearneigh(x = select(meuse, x, y) %>% as.matrix(), d1 = 0, d2 = nb.boundary.radius, row.names = NULL, longlat = NULL, bounds=c("GT", "LE"))

Preparing Elevation Data for Visualisation with rayshader

library(magrittr)
library(viridis)
library(raster)
library(rayshader)

Preparing Elevation Data for Visualisation with rayshader

library(magrittr)
library(viridis)
library(raster)
library(rayshader)
@brfitzpatrick
brfitzpatrick / ray.md
Last active July 26, 2017 00:52
fire a ray of blocks in Minecraft

Ray(s) of blocks

a function for interacting with a Minecraft world via ROpenSci's miner package

ray produces one or more rays of blocks of length rng from the fid player's position in the direction given by their view orientation (center the cross hairs on your target). Rays of lava are particularly effective for igniting enemies. Persistent rays (pst = TRUE) of some safe block type provide quick but messy staircases and bridges. If you accidentally ignite yourself, a ray of water starting adjacent to your position (disp = 1) can save you if you run into it but you'll need to type fast. Non-persistant rays replace all blocks in their path first with the block type specified by rid then with empty blocks (air type) and thus may be thought of as destroying all in their path. To ignite a pack of enemies in rapid succession set rpt to the nu