Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
🐝
Back at work

Nicholas Tierney njtierney

🐝
Back at work
View GitHub Profile
@njtierney
njtierney / qut_hpc_r_packages.R
Created November 1, 2016 00:49
Code to get the R packages installed on the QUT HPC machine
# taken from https://www.r-bloggers.com/list-of-user-installed-r-packages-and-their-versions/
ip <- as.data.frame(installed.packages()[,c(1,3:4)])
rownames(ip) <- NULL
ip <- ip[is.na(ip$Priority),1:2,drop=FALSE]
write.csv(ip, "r_package_list.csv")
print(ip, row.names=FALSE)
@njtierney
njtierney / jey_example.md
Last active November 13, 2016 06:13
plotting examples for prediction of theme park attendance
library(tidyverse)

mock_data <- tribble(
    ~park_name,                  ~count_2015,
    "DISNEY_ANIMAL_KINGDOM",        10262808.79,
    "DISNEY_CALIFORNIA_ADVENTURE", 7859777.858,
       "DISNEY_HOLLYWOOD_STUDIOS", 10161975.17,
                     "DISNEYLAND", 15850608.32,
               "DISNEYLAND_PARIS",  11303153.4,
f2 <- function(a, b, ...) {
a * 10
}
f2(10, stop("This is an error!"))
objs <- mget(ls("package:base"), inherits = TRUE)
funs <- Filter(is.function, objs)
is_not_primitive <- function(x){
@njtierney
njtierney / names_not_in.R
Created November 30, 2016 00:04
Names not in one dataframe compared to another
# find the names in one but not the other
# names(dat_dist)[((names(dat_dist) %in% names(dat_dist_aed)) == FALSE)]
@njtierney
njtierney / secret_santa.R
Created December 2, 2016 00:58
Generate secret santa lists
# this is taken from Amy Whitehead's great blog: https://amywhiteheadresearch.wordpress.com/2016/12/01/santas-little-helper/
SantasLittleHelper <- function(myFrame,guestList,conflictCols = NULL){
myTest <- TRUE
nElves <- 0
while (myTest == TRUE){
myOut <- data.frame(gifter = myFrame[,guestList],
giftee = sample(myFrame[,guestList],
replace = FALSE,
@njtierney
njtierney / openNLP_parse_annotator.Rmd
Last active December 22, 2016 01:03
Using openNLP
``` r
# running
## Requires package 'openNLPmodels.en' from the repository at
## <http://datacube.wu.ac.at>.
# install.packages("openNLPmodels.en",
# repos = "http://datacube.wu.ac.at/",
# type = "source")
@njtierney
njtierney / matrix_to_data.frame.R
Created January 4, 2017 01:31 — forked from aammd/matrix_to_data.frame.R
cantrip to turn a matrix into a data.frame, assuming that the first row of the matrix contains a header row
matrix_to_df_firstline_header <- function(mat){
requireNamespace("purrr")
mat %>%
## cut columns into lists
apply(2, function(s) list(s)) %>%
flatten %>%
map(flatten_chr) %>%
## set names to the first element of the list
{set_names(x = map(., ~ .x[-1]),
@njtierney
njtierney / extract_bibtex.md
Created January 9, 2017 09:17
Cantrip to extract bibtex from package name list
library(magrittr)
extract_bibtex <- function(x){
    purrr::map(x,
           .f = citation) %>%
    purrr::map(toBibtex)
}
@njtierney
njtierney / nick-r-style-guide.Rmd
Created January 11, 2017 01:49
A style guide that has specific rules about the pipe and ggplot
---
title: "Nick’s R Style Guide"
author: "Nicholas Tierney"
date: "12 September 2016"
output: html_document
---
I've decided to have a go at documenting my R Coding style, so that I can point at it when I want something done a certain way, but also so that I can better work out exactly what it is I prefer, and why.
This is based off of [Hadley Wickham's style guide](), with a few of my own additions regarding whitespace.
@njtierney
njtierney / crantrips.R
Created January 11, 2017 22:48
various one-ish liners from the interwebs. Not a cantrip exactly...a CRANtrip.
# combine pdfs into a single pdf.
# credit to noam ross and Thomas Leepers for this
tabulizer::merge_pdfs(c('in1.pdf', 'in2.pdf'), 'out.pdf')