Skip to content

Instantly share code, notes, and snippets.

View stephlocke's full-sized avatar

Steph Locke stephlocke

View GitHub Profile
@stephlocke
stephlocke / chartGen.R
Last active November 29, 2015 19:17
Database Conceptual Diagram
library(data.table)
library(ggplot2)
ratio<-2/3
dblayout<-rbind(
data.table(level=4,colour='DB',name='Database', start=0 ,end=1),
data.table(level=3,colour='S', name='Schema' , start=0 ,end=ratio),
data.table(level=3,colour='S', name='...' , start=ratio ,end=1),
data.table(level=2,colour='T', name='Table' , start=0 ,end=ratio^2),
data.table(level=2,colour='T', name='...' , start=ratio^2,end=ratio),
data.table(level=1,colour='C', name='Key' , start=0 ,end=ratio^3),
@stephlocke
stephlocke / geoencode.R
Last active January 9, 2016 20:41
Produce CSV of interest party responses with the locations geo-encoded
if(!require(googlesheets)) install.packages("googlesheets")
if(!require(data.table)) install.packages("data.table")
if(!require(ggmap)) install.packages("ggmap")
library(googlesheets)
library(data.table)
library(ggmap)
responses <- gs_key('1v9aEe8ov4zSGWKjaNYMFbahdDST3RN88LoI56BGzQHM', visibility = 'public', verbose = FALSE)
responses <- gs_read(responses, ws = 1, verbose = FALSE)
@stephlocke
stephlocke / miniCRAN.R
Last active January 19, 2017 09:19
Getting a local CRAN that combines internal and external packages
## ------------------------------------------------------------------------
# Set the repo for use throughout
cran <- "https://cran.rstudio.org"
# Install
if(!require(miniCRAN)){
install.packages("miniCRAN", repos = cran)
}
## ------------------------------------------------------------------------
@stephlocke
stephlocke / lastmonthOS
Created January 22, 2016 14:46
Based on cranlogs, R operating system market share of downloads last month
link<-"http://cranlogs.r-pkg.org/downloads/daily/last-month/R"
library(httr)
library(data.table)
raw<-GET(link)
rhs<-content(raw,simplify=TRUE)$downloads[[1]]
setDT(rhs)
rhs[,sum(downloads)/rhs[,sum(downloads)],os]
@stephlocke
stephlocke / SessionInfo
Last active March 4, 2016 17:19
vegaliteerror
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
@stephlocke
stephlocke / error
Created March 6, 2016 19:10
vegalite incompatability with ggvis in rmarkdown
Error in vis$data[[name]] <- data :
invalid type/length (closure/0) in vector allocation
Calls: <Anonymous> ... eval -> _fseq -> freduce -> <Anonymous> -> add_data
Execution halted
@stephlocke
stephlocke / regSSHKey.ps1
Last active November 10, 2016 13:27
Working with ssh in win10
Import-Module CredentialManager
Import-Module .\posh-git\posh-git.psm1
$keyfile = "id_rsa"
$dir = ".ssh/"
# Need to create the cred in Windows Credential Manager first (can use New-StoredCredential)
$cred = Get-StoredCredential -Target $keyfile
Add-SshKey
@stephlocke
stephlocke / stats101.Rmd
Last active March 12, 2016 13:35
Presentation code for building models iteratively
---
title: "Stats 101"
output:
revealjs::revealjs_presentation:
theme: white
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, dev="svg",
fig.height = 500)
@stephlocke
stephlocke / testingdatatable.R
Last active March 16, 2016 16:36
powerbi dataframe pickup
library(data.table)
iris1<-iris # shows up
iris2<-iris # shows up
iris3<-setDT(copy(iris)) # shows up
iris4<-setDT(copy(iris)) # doesn't show up
@stephlocke
stephlocke / keys.Rmd
Last active April 4, 2016 10:07
key setting in data.table
---
title: "data.table keys"
author: "Steph Locke"
date: "4 April 2016"
output:
md_document:
variant: markdown_github
---
# Glossary