Skip to content

Instantly share code, notes, and snippets.

Robert Krzyzanowski robertzk

View GitHub Profile
robertzk /
Last active Jul 31, 2017
Lunch & Learn 07/30/17: R environments
env <- new.env()

d <- 1
fn <- function(a, b) {
  a + b + d

fn2 <- (function() {
  d <- 2
robertzk /
Last active Apr 7, 2016
R-Python itertools rosetta stone

A translation of Python's itertools to R.

count(10) # 10 11 12 13 14 ...
count <- function(x, step = 1) {
  function() { (x <<- x + step) }
robertzk / capture_stack_trace.R
Created Jan 19, 2016
Capture an R stack trace
View capture_stack_trace.R
capture_calls <- function(e) {
e$calls <- sys.calls()
fn <- function(x) {
call_another_function(x + 1)
call_another_function <- function(y) {
robertzk / example_fn_aliasing.R
Created Jan 16, 2016
Example of function aliasing
View example_fn_aliasing.R
for (i in 1:10) {
assign(paste0("fn", i), eval(bquote(function(x) { x + .(i) })))
#' This is my function.
#' This does stuff.
#' @param x
#' @return foo.
robertzk / error_handling.R
Created Nov 2, 2015
Capture error handling in R
View error_handling.R
ref_filename <- function(ref) {
attr(ref, "srcfile")$filename
frame_text <- function(frame) {
if (identical(frame, .GlobalEnv)) {
structure(pkg = "_global",
"global environment"
robertzk / s3subset.R
Created Sep 2, 2015
S3 subsetting overloading
View s3subset.R
wrapped <- function(obj) {
structure(obj, class = "wrapped")
`[[.wrapped` <- function(obj, x) {
if (x == "predict") {
.subset2(obj, x)
} else {
.subset2(obj, "model")[[x]]
robertzk /
Last active Sep 28, 2017
Help with setting up Github PAT token

Ensure you have a Github account. Next, visit the Github help page to set up your Github auth token.

Make sure git is installed. Open up your terminal, and ensure git is installed by running which git (if you do not see git not found, then you have to do nothing). If you do not have git, run brew install git. Next, configure your git identity.

Finally, copy the authenatication token you obtained earlier, and then run the following line from your terminal (with the token replaced by your token):

echo "export GITHUB_PAT=c1e2feed3242cfa0ab2e560ce4f380f66c6e9547" >> ~/.bash_profile && source ~/.bash_profile
robertzk /
Last active Aug 29, 2015
Setting up your hipchat token.

Setting up your Hipchat API token

First, visit the Hipchat account API page. You will have to login with you hipchat account.

Scroll down and create your Hipchat token with the following permissions:

Create New Token

The token should appear in the list above. Copy the token, and then run the following line from your terminal (with the token replaced by your token):

robertzk / send.vim
Created Jul 26, 2015
vim send macro
View send.vim
let @s='^i! git add "$(git rev-parse --show-toplevel)"; git commit -m "^[$a"; git push -q origin `git rev-parse --abbrev-ref HEAD` &^[dd;w^M;@"^M^M^['
robertzk / Syberia-FAQ
Created May 31, 2015
Initial syberia FAQ
View Syberia-FAQ
Can I use CSV files? What about streaming production data? So I have this SAS file...
You can use any kind of data ingest your heart desires. The built-in import stage comes with support for many common formats (link), but it is easy to add more (link).
If you wish to use your live production data, write a package and add an import adapter (link).
What is a mungebit and why are you making up words?
A mungebit is the correct mathematical abstraction for wrangling a data set in a way that you won't have to bug a software or data engineer to make it "production ready" or live in "the data pipeline." It means you can turn the 90% of time data scientists spend on data wrangling into 10%.
You can’t perform that action at this time.