library(tidyverse)
library(rap)
library(glue)
#>
#> Attaching package: 'glue'
#> The following object is masked from 'package:dplyr':
#>
#> collapse
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, warn.conflicts = FALSE) | |
| distinct2 <- function(df, predicate_incomparable, ...) { | |
| predicate_incomparable <- enquo(predicate_incomparable) | |
| # rows for which the predicate os true for at least one variable | |
| incomparables <- filter_all(df, any_vars(!!predicate_incomparable)) | |
| # rows for which the predicate is false for all variables | |
| comparables <- filter_all(df, all_vars(!(!!predicate_incomparable))) |
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(zap) | |
| trace(wap, exit = quote({ | |
| print(f) | |
| fm <- formals(f) | |
| print(fm) | |
| sepal_length <<- fm[["Sepal.Length"]] | |
| print(rlang::node_car(sepal_length)) |
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
| # devtools::install_github("romainfrancois/zap") | |
| library(dplyr) | |
| #> | |
| #> Attaching package: 'dplyr' | |
| #> The following objects are masked from 'package:stats': | |
| #> | |
| #> filter, lag | |
| #> The following objects are masked from 'package:base': | |
| #> | |
| #> intersect, setdiff, setequal, union |
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(gapminder) | |
| library(tidyverse) | |
| library(zap) | |
| library(broom) | |
| # gapminder data for Asia only | |
| gap <- gapminder %>% | |
| filter(continent == "Asia") %>% | |
| mutate(yr1952 = year - 1952) %>% | |
| mutate(country = fct_reorder2(country, .x = year, .y = lifeExp)) |
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, warn.conflicts = FALSE) | |
| library(purrr) | |
| df <- tibble( | |
| x1 = sample(c(-1, 0, 1), size = 1000, replace = TRUE), | |
| x2 = sample(c(-1, 0, 1), size = 1000, replace = TRUE), | |
| x3 = sample(c(-1, 0, 1), size = 1000, replace = TRUE), | |
| x4 = sample(c(-1, 0, 1), size = 1000, replace = TRUE) | |
| ) |
library(rvest)
#> Loading required package: xml2
library(glue)
synonyms <- function(word) {
glue("https://www.thesaurus.com/browse/{word}") %>%
read_html() %>%
html_nodes(".synonyms-container span a[data-linkid]") %>%
html_text()
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, warn.conflicts = FALSE) | |
| iris %>% | |
| mutate_at(vars(starts_with("S")), ~if(is.factor(.)) as.character(.) else .) | |
| # https://git.io/fxnlF |
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, warn.conflicts = FALSE) | |
| iris %>% | |
| mutate_at(vars(starts_with("S")), ~if(is.factor(.)) as.character(.) else .) %>% | |
| as_tibble() | |
| # https://git.io/fxnl5 |
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
| ``` r | |
| library(rlang) | |
| grab <- function(x, i, env = baseenv(), inline = FALSE){ | |
| ex <- if (inline) { | |
| expr((!!`[`)( !!x, !!i) ) | |
| } else { | |
| expr((!!x)[!!i]) | |
| } | |
| cat("-------") |