Skip to content

Instantly share code, notes, and snippets.

Tim Mastny tmastny

Block or report user

Report or block tmastny

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fn-string-exec.R
library(rlang)
"select"(iris, Species)
fn_var <- "select"
expr((!!sym(fn_var))(iris, Species) %>% head) %>%
rlang::eval_tidy()
View embed-test.R
library(recipes)
library(embed)
library(dplyr)
library(mlbench)
set.seed(124)
data(PimaIndiansDiabetes)
d <- PimaIndiansDiabetes
View pivot_wider_exp.R
library(tidyr)
library(dplyr)
set.seed(324)
d <- tibble(
org = c(1, 1, 1, 2, 2, 3, 3, 3),
sport = c("fb", "sc", "bb", "fb", "bb", "fb", "sc", "bb"),
v1 = rnorm(8),
v2 = rnorm(8) * 2,
v3 = rnorm(8) * 10
@tmastny
tmastny / spread-pivot.R
Created Jun 4, 2019
Spread and pivot over multiple columns
View spread-pivot.R
library(tidyverse)
test <- crossing(
teamid = c(1, 2, 3),
action = c("a", "b", "c")
)
test <- test %>%
group_by(action) %>%
mutate(
day30 = c(10, 20, 30),
@tmastny
tmastny / caret-custom-model.R
Created Feb 14, 2019
Trying to get custom models for thresholds
View caret-custom-model.R
library(caret)
library(dplyr)
threshold_method <- function(method) {
thresh_code <- getModelInfo(method, regex = FALSE)[[1]]
thresh_code$type <- c("Classification")
View .inputrc
# https://unix.stackexchange.com/a/402398/286677
"\e[A": history-search-backward
"\e[B": history-search-forward
@tmastny
tmastny / meaning-chains.R
Created Aug 30, 2018
Meaning chains with word embeddings
View meaning-chains.R
# http://sappingattention.blogspot.com/2018/06/meaning-chains-with-word-embeddings.html
cpath = function(matrix, w1, w2, blacklist = c()) {
p1 = matrix[[w1]]
p2 = matrix[[w2]]
base_similarity = cosineSimilarity(p1, p2)
pairsims = matrix %*% t(rbind(p1, p2))
# Words closer to *either* candidate than the other word. These might be used eventually; mostly to save on computation in later steps.
decentsims = pairsims[apply(pairsims, 1, max) >= base_similarity[1],]
@tmastny
tmastny / rstudio
Created Aug 21, 2018
put in bin to launch rstudio app (can even use to open files)
View rstudio
#!/bin/bash
open -a "RStudio" "$@"
@tmastny
tmastny / R
Created Aug 21, 2018
put in bin for nice R executable
View R
#!/bin/bash
RLINK='/Library/Frameworks/R.framework/Resources/bin/R'
if [ -z "$*" ]
then
# /usr/local/bin/R --no-save --no-restore-data --quiet
$RLINK --no-save --no-restore-data --quiet
else
# /usr/local/bin/R "$@"
$RLINK "$@"
fi
View Makevars
# .R/Makevars
# debug unoptimized build
# CFLAGS += -g -O0 -Wall
# CXXFLAGS += -g -O0 -Wall
# CXX11FLAGS += -g -O0 -Wall
MAKE = make -j5
You can’t perform that action at this time.