- To make it easier for others to re-use your code.
- To signify that your code adheres to certain conventions agreed upon by the community.
At minimum: a collection of R scripts in a directory called R/
+ a DESCRIPTION
file
library(tidyverse) | |
f <- function(dat, colname) { | |
varname <- rlang::as_name(rlang::enquo(colname)) | |
new_df <- data.frame(x = c('a','b','c')) %>% | |
mutate({{varname}} := dat %>% pull({{ colname }})) | |
return(new_df) | |
} | |
df1 <- data.frame(a = 1:3, b = 4:6) | |
df1 %>% f(a) |
ColorBrewer.R linguist-vendored=true |
#' --- | |
#' output: | |
#' md_document: | |
#' pandoc_args: | |
#' - '--from=markdown-implicit_figures' | |
#' - '--to=commonmark' | |
#' - '--wrap=preserve' | |
#' --- | |
# practice with custom conditions | |
# https://adv-r.hadley.nz/conditions.html#custom-conditions | |
library(dplyr) | |
abort_bad_argument <- function(arg, must, not = NULL) { | |
msg <- glue::glue("`{arg}` must {must}") | |
if (!is.null(not)) { | |
not <- typeof(not) | |
msg <- glue::glue("{msg}; not {not}.") | |
} |
pick_something <- function(choice) { | |
ifelse(choice == 'list', | |
list("here's", "your", "list"), | |
"this isn't a list") | |
} | |
pick_something('anything_else') | |
#> [1] "this isn't a list" | |
pick_something('list') | |
#> [[1]] |
--- | |
date: "2020-05-04" | |
output: | |
github_document: | |
html_preview: false | |
--- | |
```{r, include=FALSE} | |
knitr::opts_chunk$set(fig.path = here::here()) | |
``` |
library(tidyverse) | |
ross_data <- read_csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/bob-ross/elements-by-episode.csv", | |
col_types="ccddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd") %>% | |
mutate(TITLE = gsub("\\\"", '', TITLE)) | |
themes <- c('MOUNTAIN', 'WINTER', 'AUTUMN', 'LAKE', 'CABIN') | |
############################################################# | |
# Part 1 - fill in the blanks each line of the function |
Update: these notes are now here: https://sovacool.dev/posts/2019/12/urssi-winterschool-notes
Slides & other resources: https://github.com/si2-urssi/winterschool
Contents: