Skip to content

Instantly share code, notes, and snippets.

View abresler's full-sized avatar

Alex Bresler abresler

View GitHub Profile
@andrie
andrie / cran-package-communities.R
Last active August 29, 2015 14:11
Determine CRAN package clusters (communities)
## Determine CRAN package clusters (communities)
library(miniCRAN)
library(igraph)
library(magrittr)
# Download matrix of available packages at specific date ------------------
@timelyportfolio
timelyportfolio / code.R
Created January 8, 2015 19:34
use twitter text javascript in R with V8
# devtools::install_github("jeroenooms/curl")
# devtools::install_github("jeroenooms/V8")
library(V8)
ct = new_context()
# get source and remove anonymous function wrapper
t = readLines(
"https://raw.githubusercontent.com/twitter/twitter-text/master/js/twitter-text.js"
@hrbrmstr
hrbrmstr / tempanomaly.R
Created January 18, 2015 14:25
NASA GISS’s Annual Global Temperature Anomaly Trends
library(httr)
library(magrittr)
library(dplyr)
library(ggplot2)
# data retrieval ----------------------------------------------------------
pg <- GET("http://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts+dSST.txt",
user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A"))
@timelyportfolio
timelyportfolio / code.R
Last active August 29, 2015 14:13
example of how to define graph in DiagrammeR for graphviz
library(DiagrammeR)
mat <- structure(
c(0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1,
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1,
0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
@timelyportfolio
timelyportfolio / Readme.md
Last active August 29, 2015 14:14
R finance charts with the svgPanZoom htmlwidget
@jeroen
jeroen / viz.js.R
Last active August 29, 2015 14:15
library(V8)
stopifnot(packageVersion("V8") >= "0.5")
# Create V8 context and load viz.js
ct <- new_context("window")
invisible(ct$source('http://mdaines.github.io/viz.js/viz.js'))
# This runs: Viz("digraph { a -> b; }", "svg")
svg <- ct$call("Viz", "digraph { a -> b; }", "svg")
cat(svg)
@rich-iannone
rich-iannone / chromatography.R
Last active August 29, 2015 14:16
R function that loads in chromatography.js, constructs a string of JS code, passes that code for evaluation (using the 'V8' package), and returns a palette of visually different colors.
library(V8)
# Create function to generate palette of visually different colors
hex_palette <- function(no_colors,
hue_range = NULL,
chroma_range = NULL,
lightness_range = NULL){
pal <- function(col, border = "light gray", ...){
n <- length(col)

geojsonio has two ways to validate geojson (specifically geojson, not json structure itself). Via a web API from geojsonlint, or locally using the Mapbox's javascript geojsonhint library (included in the package).

Both can act directly on many different inputs, including character strings, lists, data.frame's, all the sp class spatial objects.

Install and load

@hrbrmstr
hrbrmstr / sgmarkerex.R
Created March 13, 2015 01:36
state unemployment example for blog post
library(dplyr)
library(streamgraph)
library(pbapply)
# Grab some employment data from BLS --------------------------------------
url <- "http://www.bls.gov/lau/ststdsadata.txt"
dat <- readLines(url)
# Small function to grab data for a particular state ----------------------
@timelyportfolio
timelyportfolio / shinyApp.R
Last active August 29, 2015 14:17
forked from @rich-iannone dogs example
# Obtain 'dogs.csv'
# Created by Alex Bresler, available at:
# https://github.com/abresler/abresler.github.io/blob/master/blog/2015/february/exploring_agility_show/data/dogs.csv
dat_url <- "http://asbcllc.com/blog/2015/february/exploring_agility_show/data/dogs.csv"
dogs <- read.csv(dat_url, header = TRUE, stringsAsFactors = FALSE)
library(shiny)
# Install the latest DiagrammeR package from GitHub
# devtools::install_github("rich-iannone/DiagrammeR")