devtools::install_github("tidyverse/dplyr", ref = "feature-341-zero-length-groups")
# [...]
library(dplyr)
# [...]
d <- data_frame(
f = factor(c("a", "b"), levels = c("a", "b", "c")),
x = 1:2
)
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(purrr) | |
library(dplyr) | |
#> | |
#> Attaching package: 'dplyr' | |
#> The following objects are masked from 'package:stats': | |
#> | |
#> filter, lag | |
#> The following objects are masked from 'package:base': | |
#> |
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(purrr) | |
library(dplyr) | |
#> | |
#> Attaching package: 'dplyr' | |
#> The following objects are masked from 'package:stats': | |
#> | |
#> filter, lag | |
#> The following objects are masked from 'package:base': | |
#> |
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> | |
using namespace Rcpp; | |
List foo(){ | |
return List::create(1, 2, 3 ) ; | |
} | |
NumericMatrix bar(){ | |
return NumericMatrix(10, 10); | |
} |
library(purrr)
library(rlang)
#>
#> Attaching package: 'rlang'
#> The following objects are masked from 'package:purrr':
#>
#> %@%, %||%, as_function, flatten, flatten_chr, flatten_dbl,
#> flatten_int, flatten_lgl, invoke, list_along, modify, prepend,
#> rep_along, splice
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("-------") |
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
library(dplyr, warn.conflicts = FALSE) | |
iris %>% | |
mutate_at(vars(starts_with("S")), ~if(is.factor(.)) as.character(.) else .) | |
# https://git.io/fxnlF |
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) | |
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) | |
) |