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
--- | |
title: "Summarise and mutate multiple columns" | |
output: html_document | |
--- | |
```{r, include = FALSE} | |
library(dplyr) | |
knitr::opts_hooks$set( | |
asciicast = rsciinema::asciicast_hook | |
) |
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(rlang) | |
library(dplyr) | |
library(purrr) | |
mutate_when <- function(data, condition, ...){ | |
condition <- enquo(condition) | |
dots <- exprs(...) |
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(prenoms) | |
library(babynames) | |
library(ggplot2) | |
library(dplyr) | |
nnames <- function(data, origin){ | |
data %>% | |
group_by(sex, year) %>% | |
summarise(n = length(unique(name))) %>% | |
mutate( origin = origin ) %>% |
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(rlang) | |
library(dplyr) | |
library(purrr) | |
replace_when <- function(data, target, ...){ | |
target <- ensym(target) | |
mutate( data, !!target := case_when( !!!quos(...), TRUE ~ !!target ) ) | |
} | |
d <- data.frame(x = 1:10, y = 1:10) |
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(css) | |
library(glue) | |
library(rvest) | |
library(stringr) | |
library(dplyr) | |
library(purrr) | |
directory <- "https://github.com/rstudio/rstudio/blob/master/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/themes" | |
raw_directory <- "https://raw.githubusercontent.com/rstudio/rstudio/master/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/themes" | |
rstudio_theme_names <- read_html(directory) %>% |
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(dplyr) | |
library(purrr) | |
library(rlang) | |
derange <- function(data, ..., by_group = FALSE){ | |
arrange( data, !!!map( quos(...), ~ quo(desc(!!.)) ), by_group = by_group ) | |
} | |
d <- data.frame( x = 1:10, y = letters[1:10]) | |
derange(d, x, y) |
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) | |
library(scales) | |
# bc who column names are weird | |
parse_percentile <- function(x){ | |
x <- str_replace( x, "^P", "" ) | |
case_when( | |
x == "01" ~ .1, | |
x == "999" ~ 99.9, | |
TRUE ~ as.numeric(x) |
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(purrr) | |
library(dplyr) | |
row_count <- function(.x, .f){ | |
.f <- as_mapper(.f) | |
reduce(.x, function(x, y) x + .f(y), .init = 0 ) | |
} | |
data <- tribble( | |
~x, ~y, ~z, |
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) | |
# devtools::install_github( "ThinkR-open/uni" ) | |
uni::code %>% | |
filter( !is.na(languages) ) %>% | |
pull(languages) %>% | |
str_split(", ") %>% | |
flatten_chr() %>% | |
unique() |
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
#include <Rcpp.h> | |
#include <RcppParallel.h> | |
// [[Rcpp::depends(RcppParallel)]] | |
// [[Rcpp::plugins(cpp11)]] | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
int count_baseline( NumericVector x ){ | |
return std::count( x.begin(), x.end(), 3.0 ) ; |