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
| pMap <- function(.l, .f, ...) { | |
| .f <- rlang::as_function(.f, ...) | |
| if (rlang::is_named(.l)) { | |
| fun <- function(...) { | |
| rlang::fn_env(.f) <- rlang::env(...) | |
| .f(...) | |
| } | |
| } else { | |
| fun <- .f |
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
| #' Uncomfortable data | |
| #' LA R Users Group | |
| #' 2020-09-22 | |
| #' Edward Visel | |
| #' Setup | |
| library(tidyverse) | |
| path <- '/tmp/nycflights13/flights.csv' |
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
| alistaire <- function(n){ | |
| two_rows <- rep(seq_len(n/2L), each = 4L) | |
| out_mat <- matrix(0L, n, n) | |
| index_mat <- matrix(seq_len(n), nrow = 2L) | |
| for (i in seq_len(n/2L)){ | |
| out_mat[index_mat[, i], ] <- two_rows | |
| two_rows <- two_rows + 1L | |
| } | |
| out_mat | |
| } |
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(gganimate) | |
| animate( | |
| crossing( | |
| p = seq(0.1, 5, by = 0.1), | |
| theta = seq(0, 2*pi, length.out = 101) | |
| ) %>% | |
| mutate(r = 1 / (abs(cos(theta))^p + abs(sin(theta))^p)^(1/p)) %>% | |
| ggplot(aes(theta, r, fill = p)) + |
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(gganimate) | |
| p <- crossing(t = (1:4)*pi/2, | |
| x = seq(0, 2*pi, length = 501)) %>% | |
| mutate(y = 2 - 2*sin(x) + sin(x) * sqrt(abs(cos(x)))/(sin(x) + 1.4), | |
| x = (x + t) %% (2*pi)) %>% | |
| ggplot(aes(x, y, color = x)) + | |
| geom_path(size = 2, show.legend = FALSE) + | |
| scale_color_gradient2(low = '#7a0177', mid = '#f768a1', high = '#fcc5c0') + |
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(ggplot2) | |
| library(gganimate) | |
| ### Horizontal rotation | |
| p <- data_frame(x = c(-4, 0, 4), y = c(0, 3, 0), state = 1) %>% | |
| bind_rows(mutate(., x = -x, state = 2)) %>% # frame flipped over y-axis | |
| ggplot(aes(x, y, ymin = y, ymax = y + 1)) + | |
| geom_ribbon() + |
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
| coalesce_join( | |
| tribble( | |
| ~key, ~var1, ~var2, | |
| 'a', 1, NA, | |
| 'b', NA, 2 | |
| ), | |
| tribble( | |
| ~key, ~var1, ~var2, | |
| 'a', NA, 1, | |
| 'b', 2, NA |
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: "Pythagorean Triples" | |
| author: "Edward Visel" | |
| output: | |
| html_document: | |
| df_print: paged | |
| --- | |
| ```{r} | |
| library(tidyverse) |
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
| # base R version | |
| read.markdown <- function(file, stringsAsFactors = FALSE, strip.white = TRUE, ...){ | |
| if (length(file) > 1) { | |
| lines <- file | |
| } else if (grepl('\n', file)) { | |
| con <- textConnection(file) | |
| lines <- readLines(con) | |
| close(con) | |
| } else { | |
| lines <- readLines(file) |
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(rvest) | |
| library(tidyverse) | |
| h <- read_html('https://projects.fivethirtyeight.com/congress-trump-score/house/') | |
| trump_score <- h %>% | |
| html_nodes('table.member-list') %>% | |
| map(html_table, fill = TRUE) %>% | |
| set_names(c('Senate', 'House')) %>% | |
| map(set_names, |
NewerOlder