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(purrr) | |
library(dplyr) | |
na_set <- function(x, p){ | |
p <- as_mapper(p) | |
x[p(x)] <- NA | |
x | |
} | |
# or something like this using case_when |
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(rvest) | |
library(glue) | |
inclusivise <- function( mot = "étudiant" ){ | |
url <- glue( "http://www.larousse.fr/dictionnaires/rechercher/?q={mot}&l=francais&culture=" ) | |
mots <- url %>% | |
read_html() %>% | |
html_node(".AdresseDefinition") %>% |
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 ; | |
// [[Rcpp::plugins(cpp11)]] | |
template <int RTYPE> | |
Vector<RTYPE> rotate_impl( Vector<RTYPE> x, int pivot ){ | |
auto n = x.size() ; | |
Vector<RTYPE> res = no_init(n) ; |
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
/* clang++ -std=c++14 timing.cc -o timing -g -Wall -O3 */ | |
#include <time.h> | |
#include <math.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <locale.h> | |
#include <algorithm> |
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 ; | |
// [[Rcpp::plugins(cpp11)]] | |
inline uint64_t as_uint64_t(double x){ | |
return *reinterpret_cast<uint64_t*>( &x ) ; | |
} | |
inline uint64_t quiet_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
#include <Rcpp.h> | |
#include <RcppParallel.h> | |
// [[Rcpp::depends(RcppParallel)]] | |
// [[Rcpp::plugins(cpp11)]] | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
int count_baseline( NumericVector x ){ | |
return std::count( x.begin(), x.end(), 3.0 ) ; |
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) | |
# devtools::install_github( "ThinkR-open/uni" ) | |
uni::code %>% | |
filter( !is.na(languages) ) %>% | |
pull(languages) %>% | |
str_split(", ") %>% | |
flatten_chr() %>% | |
unique() |
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(purrr) | |
library(dplyr) | |
row_count <- function(.x, .f){ | |
.f <- as_mapper(.f) | |
reduce(.x, function(x, y) x + .f(y), .init = 0 ) | |
} | |
data <- tribble( | |
~x, ~y, ~z, |
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(scales) | |
# bc who column names are weird | |
parse_percentile <- function(x){ | |
x <- str_replace( x, "^P", "" ) | |
case_when( | |
x == "01" ~ .1, | |
x == "999" ~ 99.9, | |
TRUE ~ as.numeric(x) |
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(purrr) | |
library(rlang) | |
derange <- function(data, ..., by_group = FALSE){ | |
arrange( data, !!!map( quos(...), ~ quo(desc(!!.)) ), by_group = by_group ) | |
} | |
d <- data.frame( x = 1:10, y = letters[1:10]) | |
derange(d, x, y) |