Skip to content

Instantly share code, notes, and snippets.

View siuba-call.py
from siuba.siu import strip_symbolic, _
import pandas as pd
d = pd.DataFrame({'a':[1], 'b':[1]})
call = _.a + _.b
call(d)
View ipython-autocomplete2.py
# dynamically objects to completion
class Shape3():
area = 1
perimeter = 1
location = 1
shape_dict = {}
def __getitem__(self, key):
if hasattr(self, key):
View ipython-autocomplete.py
# References:
# https://ipython.readthedocs.io/en/stable/config/integrating.html
# https://stackoverflow.com/questions/17974777/tab-complete-dictionary-keys-in-ipython
class Shape2():
area = 1
perimeter = 1
location = 1
def __getitem__(self, key):
View test.Rmd
---
title: "test"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{test}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
View tidylo-example.R
library(dplyr)
library(janeaustenr)
library(tidytext)
library(tidylo)
library(ggplot2)
tidy_bigrams <- austen_books() %>%
unnest_tokens(bigram, text, token = "ngrams", n = 2)
# bigrams across books
View model-path.R
library(sagemaker)
s3_bucket()
#> [1] "sagemaker-us-east-2-495577990003"
tune <- sagemaker_attach_tuner("xgboost-191114-1954")
sagemaker:::model_artifact_s3_path(tune$model_name)
#> [1] "s3://sagemaker-us-east-2-495577990003/models/xgboost-191114-1954-002-e66e00d3/output/model.tar.gz"
View url-test.R
# https://github.com/tmastny/sagemaker/blob/4d64375bdf4019cc0bf82a7ff4d6d97ea134f103/R/install.R#L29
library(stringr)
library(git2r)
library(magrittr)
print.github_url <- function(x, ...) {
cat(x)
invisible(x)
}
View reorder-within-reprex.R
library(tidytext)
library(ggplot2)
library(dplyr)
diamonds %>%
filter(cut %in% c("Fair", "Good")) %>%
count(price = ifelse(price < 2500, "lo", "hi"), cut, clarity) %>%
mutate(clarity = reorder_within(clarity, n, cut)) %>%
ggplot(aes(clarity, n)) +
geom_col() +
@tmastny
tmastny / open-files.sh
Last active Apr 22, 2020
Open files that were modified or are new to current branch
View open-files.sh
# also works with sublime (subl)
code $(git diff --name-only master)
# relative is also useful depending on your working directory
code $(git diff --relative --name-only master)
@tmastny
tmastny / transpose-summary-row.R
Created Apr 7, 2020
Use dplyr 1.0.0 rowwise to add summary rows
View transpose-summary-row.R
library(ggplot2)
library(tidyr)
library(dplyr, warn.conflicts = FALSE)
diamonds_sum <- diamonds %>%
mutate(across(cut, as.character)) %>%
group_by(cut) %>%
summarise(across(price, sum), across(carat, n_distinct), n = n())
diamonds_sum
You can’t perform that action at this time.