Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
🌴
On vacation

Nicholas Tierney njtierney

🌴
On vacation
View GitHub Profile
project
|- DESCRIPTION # project metadata and dependencies
|- README.md # top-level description of content and guide to users
|- NAMESPACE # exports R functions in the package for repeated use
|- LICENSE # specify the conditions of use and reuse of the code, data & text
|- data/ # raw data, not changed once created
| +- my_data.csv # data files in open formats such as TXT, CSV, TSV, etc.
|
|- analysis/ # Series of folders for each step of the analysis
@njtierney
njtierney / copula-example.R
Last active October 20, 2016 01:54
R copula code exampl
# install.packages("VineCopula")
# install.packages("copula")
# install.packages("tigerstats")
library(VineCopula)
library(copula)
library(tigerstats)
set.seed(123)
N=200
dim=dim
@njtierney
njtierney / qut_hpc_r_packages.R
Last active November 1, 2016 00:48
QUT HPC R packages, as of 31/10/2016 @ 17:50
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, "package_list.csv")
print(ip, row.names=FALSE)
@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]),