Skip to content

Instantly share code, notes, and snippets.

View tomschenkjr's full-sized avatar

Tom Schenk Jr tomschenkjr

View GitHub Profile
[
// Modified Sublime-REPL keybindings for an "R-friendly" set of shortcuts.
// Copy and paste this text into the Key Bindings - User (under Preferences menu).
// For more information, see http://tomschenkjr.net/2012/05/17/using-sublime-text-2-for-r/
// Executes a selection of text in REPL, latter only displays code and does not execute
{ "keys": ["ctrl+shift+r"], "command": "repl_transfer_current", "args": {"scope": "selection"}},
{ "keys": ["ctrl+shift+r", "r"], "command": "repl_transfer_current", "args": {"scope": "selection", "action":"view_write"}},
// Executes the entire file (build) in REPL, latter only displays code and does not execute
@tomschenkjr
tomschenkjr / send-to-R-new-line.sublime-macro
Created June 5, 2012 17:20
Send a selection of code to R using SublimeREPL and move cursor to new line
// Purpose: This is a macro which will send a selection of text to sublimeREPL.
// Note: Add this to your macros, which can be accessed from Tools > Macros or saving to your Sublime Text Packages folder.
[
{"command": "repl_transfer_current", "args": {"scope": "selection"}}
{"command": "move", "args": {"by": "lines", "forward": true}}
]
@tomschenkjr
tomschenkjr / export-socrata.R
Last active May 5, 2017 22:34
An alpha of a export.socrata() function for the RSocrata package. See https://github.com/Chicago/RSocrata/issues/126
library(devtools)
install_github("Chicago/RSocrata" ref = "issue124") # RSocrata 1.7.2-7 or above
library(RSocrata)
#' Exports CSVs from Socrata data portals
#'
#' Input the URL of a data portal (e.g., "data.cityofchicago.org") and
#' will download all CSV files (no other files supported) and saved in
#' a single directory named after the root URL (e.g., "data.cityofchicago.org/").
#' Downloaded files are compressed to GZip format and timestamped so the download
@tomschenkjr
tomschenkjr / ggplot2-tutorial-hw-maps.R
Created November 7, 2012 22:55
ggplot2 Workshop Homework for Maps
# TITLE: ggplot2 Workshop Homework for Maps
# AUTHOR: Tom Schenk Jr.
# DATE CREATED: November 7, 2012
# DATE MODIFIED: None
# PURPOSE: Create maps using R and ggplot2 library.
# LIBRARIES: ggplot2, maptools
library(ggplot2)
library(maptools)
@tomschenkjr
tomschenkjr / tidy-api-downloader.R
Last active May 15, 2020 19:55
This is a conceptual study to leverage the tidyverse syntax and lazy evaluation concepts (influenced by sparklyr) to approach API wrapper packages.
# This is a conceptual study to leverage the tidyverse syntax and lazy
# evaluation concepts (influenced by sparklyr) to approach API wrapper packages.
#
# Problem statement: API wrappers often require users to download *all* data
# to manipulate and filter the information. Some packages support custom
# queries but often complicate syntax by adding many parameters within the
# function that may be hard for data scientists to formulate.
#
# Potential solution: API queries can be separated into three principal parts.
# First, to query the API metadata to understand column names and data types.
@tomschenkjr
tomschenkjr / R-in-sublime-text-2-demonstration.R
Created June 5, 2012 18:47
Example file for Sublime Text for R tutorial
# TITLE: R in Sublime Text 2 Demonstration
# AUTHOR: Tom Schenk Jr.
# DATE: May 15, 2012
# R as a calculator
2 + 2 # After you adjust the keybindings
sqrt(9) # Syntax should differentiate between function and variable.
sin(pi) # See if there is a floating point issue.
# Install Packages
Public Function BASE64SHA1(ByVal sTextToHash As String)
Dim asc As Object
Dim enc As Object
Dim TextToHash() As Byte
Dim SharedSecretKey() As Byte
Dim bytes() As Byte
Const cutoff As Integer = 5
Set asc = CreateObject("System.Text.UTF8Encoding")
@tomschenkjr
tomschenkjr / reshape-tutorial.R
Created November 19, 2012 01:56
Chicago Data Visualization reshape Tutorial Script
# Install reshape package. You will be asked to pick a server.
install.packages("reshape")
# We're going to also use ggplot2, so let's install that as well:
install.packages(c("reshape","ggplot2")) # In R, c() concatenates inputs as a vector
# You will always need to load the libraries after installing the package.
library(reshape)
library(ggplot2)