Skip to content

Instantly share code, notes, and snippets.

View romainfrancois's full-sized avatar
🎉
tada⬢science ⬡⬡ ex(Posit/RStudio, ThinkR, Mango Solutions)

Romain François romainfrancois

🎉
tada⬢science ⬡⬡ ex(Posit/RStudio, ThinkR, Mango Solutions)
View GitHub Profile
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))
# 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
library(zap)
trace(wap, exit = quote({
print(f)
fm <- formals(f)
print(fm)
sepal_length <<- fm[["Sepal.Length"]]
print(rlang::node_car(sepal_length))
library(tidyverse)
library(rap)
library(glue)
#> 
#> Attaching package: 'glue'
#> The following object is masked from 'package:dplyr':
#> 
#>     collapse
@romainfrancois
romainfrancois / distinct2.r
Last active December 19, 2018 11:43
distinct with incomparable
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)))
library(dplyr, warn.conflicts = FALSE)
library(purrr)
expressions <- function(vars, funs) {
#' make_expr("mpg", mean)
make_expr <- function(var, fun) {
expr((!!fun)(!!sym(var)))
}
library(dplyr, warn.conflicts = FALSE)
library(purrr)
named_group_split <- function(...) {
data <- group_by(...)
names <- group_keys(data) %>%
map(as.character) %>%
reduce(paste, sep = "~~")
library(purrr)
library(rap)
library(gapminder)
library(dplyr, warn.conflicts = FALSE)
oceania <- gapminder::gapminder %>%
filter(continent == "Oceania") %>%
mutate(yr1952 = year - 1952) %>%
select(-continent) %>%
if(interactive()) {
.__Rprofile_env__. <- new.env(parent = emptyenv())
.__Rprofile_env__.[["install"]] <- pak::pkg_install
attach(.__Rprofile_env__.)
library(usethis, warn.conflicts = FALSE)
library(conflicted)
conflict_prefer("filter", "dplyr")
conflict_prefer("sql", "dbplyr")
library(tidyverse)
library(rtweet)
library(glue)
library(rtweet)
# likes <- <chr vector of accounts that liked the tweet>
# retweets <- <chr vector of accounts that retweeted the tweet>
data <- tibble(
user = c(likes, retweets),