Skip to content

Instantly share code, notes, and snippets.

💖
Sparkly

Danielle Navarro djnavarro

💖
Sparkly
Block or report user

Report or block djnavarro

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
@djnavarro
djnavarro / ascii-brain.R
Created Oct 30, 2018
image of a brain constructed using the ASCII chars in an R command
View ascii-brain.R
library(tidyverse)
library(imager)
# function to convert an image to an ascii character map
asciify <- function(file, charset, threshold){
# load image
im <- load.image(file)
im <- as.cimg(im[,,1:3])
View .Rprofile
if(interactive()) {
# packages helpful for development
suppressMessages({
require(devtools)
require(usethis)
require(testthat)
require(roxygen2)
require(git2r)
@djnavarro
djnavarro / censor.R
Last active Jul 10, 2019
quick and dirty code for systematic censoring
View censor.R
library(tidyverse)
# define the censoring function
censor_smoking <- function(df) {
# (this code is awful I am so sorry)
df <- df %>%
rowwise() %>% # ugh... rowwise
mutate(keep_case = case_when(
(sex.factor == "Male" & runif(1) < .3) ~ 0, # censor male with prob .3
@djnavarro
djnavarro / pipe_bitch.R
Created Jul 3, 2019
source code to "pipe bitch"
View pipe_bitch.R
pipe_bitch <- tibble::tibble(
line = 1:80,
lyric = c(
"you wanna?",
"you wanna?",
"",
"you wanna code tidy?",
"you wanna R party?",
"you wanna be Shiny?",
"you better pipe bitch",
@djnavarro
djnavarro / nse_hell.R
Created May 23, 2019
passing user expressions to inner functions, tidyeval and base
View nse_hell.R
# tidyeval version: tidy_outer returns
# the user expression
#
# expr quotes you
# enexpr quotes user
tidy_outer <- function(x) {
tidy_inner(!!rlang::enexpr(x))
}
View osf_download.R
# authenticate using OSF token stored in .Renviron
osfr::osf_auth()
# define download function
download_project <- function(node, path) {
proj <- osfr::osf_retrieve_node(node)
files <- osfr::osf_ls_files(proj)
if(!dir.exists(path)) dir.create(path)
for(i in 1:nrow(files)) {
cat("downloading: ", files$name[i], "\n")
@djnavarro
djnavarro / coord_trans_example.R
Last active May 13, 2019
example where coord_trans throws many warnings
View coord_trans_example.R
# from section 7.5.1 of ggplot2 book
library(ggplot2)
base <- ggplot(diamonds, aes(carat, price)) +
stat_bin2d() +
geom_smooth(method = "lm") +
xlab(NULL) +
ylab(NULL) +
theme(legend.position = "none")
@djnavarro
djnavarro / transition_filter_bayes.R
Created Apr 17, 2019
gganimated version of ASCII Bayes
View transition_filter_bayes.R
library(tidyverse)
library(asciify)
library(gganimate)
p <- ascii_data("bayes.png") %>%
ascii_map(
alphabet = as.character(0:9),
rescale = .15) %>%
ascii_plot(charsize = 4)
@djnavarro
djnavarro / mouse_to_cat.R
Created Mar 29, 2019
Transform mouse emoji into cat emoji
View mouse_to_cat.R
library(tidyverse)
library(fontr)
library(emojifont)
library(ggpolypath)
library(transformr)
library(animation)
library(Cairo)
# create the base images from cat emoji and mouse emoji!
cat <- glyph_polygon(ch = emoji("cat"), family = "EmojiOne")
@djnavarro
djnavarro / ggplot2_geomvector.R
Created Mar 30, 2019
Custom ggplot2 geom that plots a (subset of a) vector field
View ggplot2_geomvector.R
library(ggplot2)
library(dplyr)
library(tibble)
library(tidyr)
GeomVector <- ggproto("GeomVector", Geom,
required_aes = c("x", "y", "direction", "length"),
default_aes = aes(
You can’t perform that action at this time.