Skip to content
{{ message }}

Instantly share code, notes, and snippets.  Finishing up 2020

# Nicholas Tierney njtierney Finishing up 2020
Created Oct 12, 2020
View wa-hikes.md
``````bushwalk_url <- "http://trailswa.com.au/trails/trail-types/bush-walk/"

library(polite)
library(rvest)
#> Loading required package: xml2
library(janitor)
#>
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#>
``````
Created Oct 12, 2020
View water-grid-thing.md
``````library(magrittr)
compute_posterior_water_grid <- function(n = 20,
n_water = 6,
n_land = 3,
prior = rep(x = 1,times = n),
p_grid = seq(from = 0,
to = 1, length.out = n)){

# define posterior
# p_grid <- seq(from = 0, to = 1, length.out = n)
``````
Created Oct 6, 2020
View halving.md
``````library(purrr)
cases <- 250
halving_thing <- function(cases, n_times){
purrr::accumulate(.x = rep(cases, n_times), .f = ~.x * 0.5)
}

halving_thing(532, 3)
#>  532 266 133
halving_thing(227, 3)
#>  227.00 113.50  56.75
``````
Created Oct 2, 2020
View example-quote-bare-vars.md
``````library(tidyverse)
my_plot <- function(data, x,y){
ggplot(data,
aes(x = {{ x }},
y = {{ y }})) +
geom_point()
}

library(palmerpenguins)
``````
Created Sep 24, 2020
View example-glm.md
``````library(tidyverse)

vec_prob <- c(6, 3, 2, 1.5, 1, 0.5, 0.1)

example_data <- crossing(
id = c(1:100),
day = 1:7
) %>%
group_by(id) %>%
mutate(sleep = sample(c("normal", "slow_wave", "REM"), size = 1)) %>%
``````
Created Sep 21, 2020
View chord-table.md
``````library(tidyverse)
library(knitr)

chord_table <- tribble(
~number, ~flavour, ~intervals,
1,       "Major 7",    "1 3 5 7",
2,       "Minor 7",    "1 b3 5 b7",
3,       "Minor 7",    "1 b3 5 b7",
4,       "Major 7",    "1 3 5 7",
5,       "Dominant 7", "1 3 5 b7",
``````
Created Sep 21, 2020
Function to generate random alpha numeric strings of a given length. Used to generate random API keys
View alpha_num.md
``````alpha_num <- function(n){

pool <- c(letters,
LETTERS,
rep(0:9, length.out = length(letters)))

paste0(
sample(x = pool,
size = n,
replace = TRUE),
``````
Created Sep 18, 2020
View map-purrr-bind_rows.md

# some things on purrr

``````# using bind_rows
head(bind_rows(one = cars,
two = cars,
.id = "anything"))
#> Error in bind_rows(one = cars, two = cars, .id = "anything"): could not find function "bind_rows"
tail(bind_rows(one = cars, two = cars, .id = "anything"))
#> Error in bind_rows(one = cars, two = cars, .id = "anything"): could not find function "bind_rows"
``````
Created Sep 4, 2020
View rename-files.R
 chapters <- list.files(pattern = "^[0-9]") new_chapters <- stringr::str_remove_all(chapters, "[0-9][0-9]-") file.rename(from = chapters, to = new_chapters) chapters <- list.files(pattern = "^[0-9]") new_chapters <- stringr::str_remove_all(chapters, "[0-9][0-9]-")
Created Aug 13, 2020
View gg-latex-image.md
```library(tidyverse)
library(palmerpenguins)
library(latex2exp)

ggplot(na.omit(penguins),
aes(x = bill_length_mm,
y = bill_depth_mm,
colour = sex)) +
geom_line() +```