Skip to content

Instantly share code, notes, and snippets.

View RobertMyles's full-sized avatar
👽

Robert Myles McDonnell RobertMyles

👽
View GitHub Profile
@RobertMyles
RobertMyles / LostPackages.R
Last active January 10, 2017 19:23
Updated R today and realized that I lost a load of packages that I had installed previously. Instead of re-installing them one by one, I just did this (it works for Mac OS, it'll be slightly different on Windows):
Old_packList <- as.list(installed.packages("/Library/Frameworks/R.framework/Versions/3.2/Resources/library"))
# here, my R version was 3.2. Change it for the R version you want the packages from!
Old <- as.character(Old_packList)
install.packages(Old)
@RobertMyles
RobertMyles / Load-Multiple-R-Packages.R
Created July 8, 2016 19:19
Load multiple packages at the same time in R
# library() or require() only load one package at a time
# but...
Packages <- c("dplyr", "ggplot2", "rstan", "readr")
lapply(Packages, library, character.only = TRUE)
# this loads as many as you put in 'Packages'. They need to be installed first, of course.
library(ggplot2)
library(scales)
library(tidyr)
library(dplyr)
rm(list=ls())
df <- structure(list(Animal = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L),
.Label = c("Buffalo", "Goat", "Sheep"),
class = "factor"),
Texture = structure(c(4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 2L, 1L, 1L, 4L, 3L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L),
.Label = c("Hard", "Semi-Hard", "Semi-Soft", "Soft"),
#### Make 2-page color table of all colors available in R ####
# R color convention is color, color1, color2, color3, and color4
# with shades getting progressively darker
# For example skyblue, skyblue1, skyblue2, skyblue3, skyblue4
# This table prints only the full name, and fullname4 if available
# This table does not show greyscale colors grey0:grey100
# R colors minus 100 shades of grey
cols = colors()[c(2:151,362:657)]
@RobertMyles
RobertMyles / gganimate_beta_simulation.R
Created August 31, 2016 14:03 — forked from mrecos/gganimate_beta_simulation.R
Code for a ggplot2/gganimate version of Cory's Bayesian updating animation: https://gist.github.com/cjbayesian/3373348
# packages
library("ggplot2")
# devtools::install_github("dgrtwo/gganimate")
library("gganimate")
library("dplyr")
# set distribution parameters for simulation
p = 0.5
N = 100
y_lim = 20
a_a = 2
@RobertMyles
RobertMyles / GitHub-Forking.md
Created September 13, 2016 18:39 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, when I started going through the process of forking and issuing pull requests, I had some trouble figuring out the proper method for doing so and made quite a few mistakes along the way. I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your

@RobertMyles
RobertMyles / emojis.R
Created February 4, 2017 12:56
little script to see what emojis are available with the emojifont package in R.
library(rvest)
library(stringr)
library(emojifont)
library(tidyverse)
url <- "http://www.webpagefx.com/tools/emoji-cheat-sheet/"
page <- read_html(url)
nodes <- html_nodes(page, css = "#content")
text <- html_text(nodes)
txt <- data_frame(label = unlist(str_extract_all(text, ":[a-z_]*:"))) %>%
@RobertMyles
RobertMyles / brexit.R
Last active February 5, 2017 20:55
code for tidying up spatial UK data, for a blog post here:
library(rgdal)
library(maptools)
library(dplyr)
library(ggplot2)
library(readr)
library(httr)
library(XML)
library(ggmap)
library(scales)
@RobertMyles
RobertMyles / plotPost_2.R
Last active February 8, 2017 14:32
Modify R package BEST's plotPost function to include other font family for Brazilian Political Science Review research note
# modified by R. McDonnell. Original at: https://github.com/cran/BEST/blob/master/R/plotPost.R
# Original code by John Kruschke, modified by Mike.
plotPost_2 <-
function( paramSampleVec, credMass=0.95, compVal=NULL, ROPE=NULL,
HDItextPlace=0.7, showMode=FALSE, showCurve=FALSE, ... ) {
# Does a plot for a single parameter. Called by plot.BEST but also exported.
# Returns a histogram object invisibly.
@RobertMyles
RobertMyles / plot.BEST_2.R
Last active February 8, 2017 14:34
Modify R package BEST's plotPost function to include other font family for Brazilian Political Science Review research note
plot.BEST_2 <-
function(x, which=c("mean", "sd", "effect", "nu"), credMass=0.95,
ROPE=NULL, compVal=0, showCurve=FALSE, ...) {
# This function plots the posterior distribution for one selected item.
# Description of arguments:
# x is mcmc.list object of the type returned by function BESTmcmc.
# which indicates which item should be displayed; possible values are "mean", "sd",
# "effect" or "nu".
# ROPE is a two element vector, such as c(-1,1), specifying the limit
# of the ROPE.