Skip to content

Instantly share code, notes, and snippets.

Ben R. Fitzpatrick brfitzpatrick

Block or report user

Report or block brfitzpatrick

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@brfitzpatrick
brfitzpatrick / SLURM_foreach.md
Last active May 5, 2019
minimal example of using `foreach` parallelism on a clusters managed by SLURM
View SLURM_foreach.md

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
View R_Script_Gen.R
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 Dec 20, 2018
Visualising Neighbourhood Weights
View vis_nb_wghts_sf.R
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"))
View schweiz_dem_rayshader.md

Preparing Elevation Data for Visualisation with rayshader

library(magrittr)
library(viridis)
library(raster)
library(rayshader)
View schweiz_dem_rayshader.md

Preparing Elevation Data for Visualisation with rayshader

library(magrittr)
library(viridis)
library(raster)
library(rayshader)
View swap values in emacs
M-x replace-regexp <RET>
\(dog\)\|cat <RET>
\,(if \1 "cat" "dog") <RET>
Beginning Line 3 with `\,` tells Emacs that this line should be evaluated as a Lisp expression.
The `\1` on Line three referres to the first grouped of characters defined with `(` and `)` on line 2.
Read line 3 as if `\1` replace with "cat" else replace with "dog"
You have to escape (i.e. preceed with `\`) the `(`, `)` and `|` characters for them to be treated as special characters
@brfitzpatrick
brfitzpatrick / ray.md
Last active Jul 26, 2017
fire a ray of blocks in Minecraft
View ray.md

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

@brfitzpatrick
brfitzpatrick / leaRn.md
Last active Jan 23, 2019
A short list of online resources for self directed learning of the R Language and Environment for Statistical Computing and Graphics
View leaRn.md

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

@brfitzpatrick
brfitzpatrick / list.files( ) + assign( )
Created Apr 22, 2016
Read all files in a directory into R
View list.files( ) + assign( )
# 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 / R2PBS.md
Last active Jan 2, 2019
How to submit R code to a Portable Batch System (PBS) managed HPC resource (e.g. QUT's High Performance Computing Facility `Lyra').
View R2PBS.md

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.

You can’t perform that action at this time.