Skip to content

Instantly share code, notes, and snippets.

Avatar

Dean Attali daattali

View GitHub Profile
@daattali
daattali / spinme
Created Feb 1, 2015
Add this at top of R script so that "source"ing the script will automatically render a markdown+HTML
View spinme
#+ spinme-chunk, eval = FALSE, echo = FALSE
.scriptName <- basename(sys.frame(1)$ofile)
.spinOutput <- knitr::spin(.scriptName, knit = TRUE)
stop(sprintf("Ignore this error - your output is ready at:\n%s",
normalizePath(.spinOutput)),
call. = FALSE)
#+ spinme-done, eval = TRUE, echo = TRUE
@daattali
daattali / S3_parent_params.R
Created May 8, 2015
S3 method does not show parent params in autocomplete
View S3_parent_params.R
# There are two humans: `human` and `angry_human`. They only differ in the fact
# that angry humans have a frown on their face.
# Example code:
# dean <- human("Dean")
# ex <- angry_human("Ex")
# plot(dean)
# plot(ex)
# When plotting `dean`, RStudio shows me all the available parameters.
View beepr_error.R
# rasmusab/beepr package is great for telling you when your R code finishes running.
# But if the code throws an error, the beep will never come, and you won't know that
# it finished running until you visually check.
# Solution: change the error handler to a failure beep.
# Example
foo <- function(success = TRUE) {
if (!success) {
stop("Error!")
}
View inheritance-argument-trouble.R
# Suppose a function has an argument "x". If a "child function" has multiple
# argument beginning with "x" and I want to pass the param "x" to its parent,
# I get error: `argument n matches multiple formal arguments`
# The reason this happens is clear, but at 3am my brain is firing blanks
# trying to find a solution. Help!
library(magrittr)
foo <- function(x, ...) UseMethod("foo")
foo.parent <- function(x, n = 5, ...) n
@daattali
daattali / bcl-data.csv
Created Nov 26, 2015
BC Liquor Store data
View bcl-data.csv
Type Subtype Country Name Alcohol_Content Price Sweetness
WINE TABLE WINE RED CANADA COPPER MOON - MALBEC 14 30.99 0
WINE TABLE WINE WHITE CANADA DOMAINE D'OR - DRY 11.5 32.99 0
WINE TABLE WINE RED CANADA SOMMET ROUGE 12 29.99 0
WINE TABLE WINE WHITE CANADA MISSION RIDGE - PREMIUM DRY WHITE 11 33.99 1
WINE TABLE WINE RED UNITED STATES OF AMERICA ZINFANDEL - BIG HOUSE CARDINAL ZIN 13.5 36.99 0
WINE TABLE WINE RED FRANCE LE VILLAGEOIS RED - CELLIERS LA SALLE 11 34.99 0
WINE TABLE WINE RED CANADA SAWMILL CREEK - MERLOT 12.5 119 0
WINE TABLE WINE WHITE CANADA SOLA 12 32.99 0
WINE TABLE WINE WHITE CANADA GANTON & LARSEN PROSPECT - PINOT BLANC BIRCH CANOE 2011 11.5 13.99 0
View STAT545A-2013-hw01_attaliDea.R
n <- 50
a <- 2
b <- -3
sigSq <- 0.5
x <- runif(n)
norm <- rnorm(n, sd = sqrt(sigSq))
y <- a + b * x + norm
plot(x,y)
abline(a, b, col = "blue")
View stat545a-2013-hw01_attali-dea.R
n <- 50
a <- 2
b <- -3
sigSq <- 0.5
x <- runif(n)
norm <- rnorm(n, sd = sqrt(sigSq))
y <- a + b * x + norm
plot(x,y)
abline(a, b, col = "blue")
View stat545a-2013-hw02_attali-dea.Rmd
Dean Attali's View of the World
========================================================
First, let's load the data and the required libraries (in this case, just lattice for plotting)
**Note:** The data is available [here](http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt)
```{r}
library("lattice")
gDat <- read.delim("gapminderDataFiveYear.txt")
```
View gist:6673238
Dean Attali
=================================
**STAT 545A hw 3**
**Sept 22 2013**
Exercises done:
* Average GDP/cap in each continent when the data was first and last collected **(easy)**
* Trimmed mean statistics for life expectancy in each continent for every year **(fun)**
* Absolute and relative world population in each of the continents **(very fun)**
* A list of all countries that at some point had their population size decrease **(very fun)**
View stat545a-2013-hw03_attali-dea
Dean Attali
=================================
**STAT 545A hw 3**
**Sept 22 2013**
Exercises done:
* Average GDP/cap in each continent when the data was first and last collected **(easy)**
* Trimmed mean statistics for life expectancy in each continent for every year **(fun)**
* Absolute and relative world population in each of the continents **(very fun)**
* A list of all countries that at some point had their population size decrease **(very fun)**