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
@romainfrancois
romainfrancois / jetlag.Rmd
Created February 3, 2018 15:09
multiple lags
``` 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':
#>
``` 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':
#>
#include <Rcpp.h>
using namespace Rcpp;
List foo(){
return List::create(1, 2, 3 ) ;
}
NumericMatrix bar(){
return NumericMatrix(10, 10);
}
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 
)
@romainfrancois
romainfrancois / frontback.md
Created April 23, 2018 08:16
select columns to front and back
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
``` r
library(rlang)
grab <- function(x, i, env = baseenv(), inline = FALSE){
ex <- if (inline) {
expr((!!`[`)( !!x, !!i) )
} else {
expr((!!x)[!!i])
}
cat("-------")
library(dplyr, warn.conflicts = FALSE)
iris %>%
mutate_at(vars(starts_with("S")), ~if(is.factor(.)) as.character(.) else .) %>%
as_tibble()
# https://git.io/fxnl5
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()
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)
)