Skip to content

Instantly share code, notes, and snippets.

View stephlocke's full-sized avatar

Steph Locke stephlocke

View GitHub Profile
@stephlocke
stephlocke / bloblogs
Last active August 29, 2015 14:14
Parsing Azure Blob logs
library(data.table)
library(chron)
library(ggplot2)
library(stringr)
# This doesn't cope with spaces in URLs grr!!
url_pattern <- "http[s]?://(?:[@blank:]|[a-zA-Z]|[0-9]|[$-_@.&+ ]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"
## Read data in from a text file
raw.log <- data.table(scan("bloblog.txt", character(0), sep = "\n"))
@stephlocke
stephlocke / Renviron.site
Created February 7, 2015 18:26
For circumventing R home user directory issues
R_USER = "E:/Dropbox/hobbies/R"
@stephlocke
stephlocke / webscraping.R
Created February 8, 2015 20:03
Gathering session data for SQLBits dashboard
library(magrittr)
library(rvest)
library(data.table)
library(stringr)
library(plyr)
# All (accepted) submitted sessions
allsubmissions <- html("https://sqlbits.com/information/PublicSessions.aspx") %>%
html_node(".session") %>%
html_table() %>%
@stephlocke
stephlocke / Console Output
Last active August 29, 2015 14:15
Example of named argument not working (as I'd expect) in magrittr
> mytestfunction(iris)
Functional sequence with the following components:
1. data.table(.)
2. { if (y) rbind(head(., 1), tail(., 1)) else .}
Use 'functions' to extract the individual functions.
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
@stephlocke
stephlocke / MWE
Created February 16, 2015 13:56
foverlaps multiple column check
library(data.table)
x<-data.table(a=c(1,2),a1=c(1,2),
b=c(1,2),b1=c(1,2),
c=c(1,2),c1=c(1,2))
y<-data.table(mina=0,maxa=3,
minb=0,maxb=3,
minc=0,maxc=3)
@stephlocke
stephlocke / app
Last active August 29, 2015 14:15
Decluttering your shiny app with modularity
source("inputcontrols.R")
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$obs), col = 'darkgray', border = 'white')
})
}
ui <- fluidPage(
sidebarLayout(
@stephlocke
stephlocke / CommunityRopes
Created February 25, 2015 21:18
Learning the Ropes Via the Community
<!DOCTYPE html>
<html>
<head>
<title>Learning the Ropes Via the Community</title>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="generator" content="pandoc" />
@stephlocke
stephlocke / basicflow
Created March 28, 2015 19:50
DiagrammeR 1st step
if (!require(DiagrammeR)) install.packages(DiagrammeR)
library(DiagrammeR)
hangs<-"graph TB
D[Data] --> R[Read into memory]
R --> DM[Data manipulation]
DM --> V[Visualisation]
DM --> O[Output]
V --> Do[Document]
Do --> O
V --> I[Interactive report]
@stephlocke
stephlocke / chartgen.R
Created May 12, 2015 15:32
theme comparisons
library(ggplot2)
library(optiRum)
basicplot<-ggplot(data=iris,
aes(x=Sepal.Width, y=Sepal.Length, colour=Species)) +
geom_point() +
stat_boxplot(fill="transparent")
multiplot(basicplot+ggtitle("theme_bw()"),
basicplot+theme_minimal()+ggtitle("theme_minimal()"),

Title

[<75 characters ideally]

Short description

[<200 characters]

Medium description