This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# create an X11 window | |
X11(width = 8, height = 8, | |
xpos = 100, ypos = 30) | |
# clear the plotting area | |
clear_plot <- function() { | |
plot.new() | |
plot.window(xlim = c(0,1), ylim = c(0,1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# version 1 of the function | |
pick_name1 <- function() { | |
names <- c("Dax", "Wug", "Lep", "Sik", "Bop") | |
sample(names)[1] | |
} | |
# version 2 of the function | |
pick_name2 <- function() { | |
names <- c("Dax", "Wug", "Lep", "Sik", "Bop") | |
sample(names, size = 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# someone else's package includes this inefficient function | |
pick_name <- function() { | |
names <- c("Dax", "Wug", "Lep", "Sik", "Bop") | |
sample(names)[1] | |
} | |
# here is my code that calls it... | |
set.seed(100) | |
print("--- Attempt 1 ---") | |
print(pick_name()) # Wug |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install.packages("remotes") | |
# remotes::install_github("djnavarro/jasmines") | |
library(jasmines) | |
set.seed(435) | |
scene_delaunay(6, 500) %>% | |
unfold_slice() %>% | |
style_ribbon( | |
palette = rainbow, | |
seed_col = "#ffffffaa", | |
alpha_init = .1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(jasmines) | |
seed_heart(2000) %>% | |
time_tempest(iterations = 20, curl_seed = 43) %>% | |
style_ribbon(palette = rainbow, alpha_decay = .1) %>% | |
export_image("~/Desktop/ozunconf1.png") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#install.packages("remotes") | |
#remotes::install_github("djnavarro/jasmines") | |
#remotes::install_github("djnavarro/fifty") | |
library(jasmines) | |
library(dplyr) | |
set.seed(125) | |
seed_heart(10000) %>% | |
mutate( | |
x = x * 35, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(DiagrammeR) | |
g <- DiagrammeR(" | |
graph TB | |
A[Is this tweet about #rstats?]-->|yes|B[Hell yeah tweet it honey!] | |
A-->|no|C[Is a statistics tweet?] | |
C-->|yes|D[Is it about statistics in psychology?] | |
D-->|no|B | |
D-->|yes|E[Are you prepared for a pointlessly heated argument?] | |
E-->|um...no|F[ARE YOU CRAZY? DO NOT TWEET THIS] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
ozmap <- function(proj4string) { | |
dat <- sf::st_transform(ozmaps::abs_ced, proj4string) | |
ggplot(dat) + | |
geom_sf() + | |
coord_sf() + | |
theme_void() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(interactive()) { | |
# packages helpful for development | |
suppressMessages({ | |
require(devtools) | |
require(usethis) | |
require(testthat) | |
require(roxygen2) | |
require(git2r) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |