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 / bench-sorted.cpp
Last active December 26, 2015 11:49
Benchmark sorted vs. unsorted grouped summarise
#include <dplyr.h>
// [[Rcpp::depends(BH,dplyr)]]
using namespace Rcpp ;
using namespace dplyr ;
class IndexHelper {
public:
IndexHelper( int pos_, int n_) : pos(pos_), n(n_){}
@romainfrancois
romainfrancois / README.md
Last active December 26, 2015 16:19
getting github issues for a given repo

Simple R script that grabs the opened issues from a github repo :

$ github_issues hadley/dplyr
   number           user                                                         title                labels
1      98         hadley                                   Setup databases with travis           enhancement
2      97         hadley                                               Unique operator           enhancement
3      96         hadley                           Implement right join and outer join           enhancement
4      95 romainfrancois                                             Hybrid evaluation enhancement, internal
5      94         hadley                 Make sure all vignettes work from R CMD check                   bug
@romainfrancois
romainfrancois / README.md
Created October 29, 2013 08:10
Log for last travis build of a project

This uses siesta to pull from travis the log for the last build of a given project.

$ travis_log hadley/dplyr | tail -n30
Le chargement a nécessité le package : methods
Le chargement a nécessité le package : siesta
* checking package vignettes in ‘inst/doc’ ... WARNING
Package vignettes without corresponding PDF/HTML:
   ‘benchmark-baseball.Rmd’
 ‘databases.Rmd’
@romainfrancois
romainfrancois / bench.R
Created November 25, 2013 17:16
Decomposing `build_index_cpp`
require(dplyr)
require(Rcpp)
require(microbenchmark)
# from the cran-logs-dply repo
logs <- readRDS("logs.rds")
# system.time( { by_day <- group_by(logs, date) } )
sourceCpp( "timings.cpp" )
@romainfrancois
romainfrancois / output.txt
Created December 14, 2013 14:07
Extract promises and their environments from ...
> f <- function(...) {
+ promises(environment())
+ }
> g <- function(x = 3, ...) {
+ z <- 4
+ f(z = z, ..., x = x)
+ }
> h <- function(..., a = 2) {
library(Rcpp)
library(microbenchmark)
vectorized <- function() {
a <- c(1, 1)
b <- c(2, 2)
for (i in 1:1000000) {
x <- a + b
}
@romainfrancois
romainfrancois / count_positive.cpp
Last active January 1, 2016 16:59
Counting the number of positives values in a numeric vector. serial and multithreaded versions.
#include <Rcpp.h>
#include <thread>
#include <future>
using namespace Rcpp ;
typedef NumericVector::iterator Iterator ;
struct count_positive {
int operator()(Iterator first, Iterator last){
ndiff <- 2597797
f <- function(){
n <- round(runif( 1, min = 4, max = 10 ))
paste( sample(letters, n, replace = TRUE ), collapse = "" )
}
a <- replicate( ndiff, f() )
b <- replicate( ndiff, f() )
rows <- sample( 1:ndiff, 3018671, replace = T )
cols <- sample( c(T,F), 3018671, replace = T )
@romainfrancois
romainfrancois / results.txt
Created January 9, 2014 13:54
Simple implementation of which using threads in C++11
> bench(1000)
Unit: microseconds
expr min lq median uq max neval
which(b) 2.104 4.548 5.1000 6.0955 18.306 100
which_cpp_nthreads(b, 2) 26.401 28.303 28.9285 30.0625 103.980 100
which_cpp_nthreads(b, 4) 45.902 49.494 50.6335 52.1155 115.184 100
which_cpp_nthreads(b, 8) 97.596 100.143 101.3720 104.9895 270.521 100
> bench(1e+05)
Unit: microseconds
@romainfrancois
romainfrancois / internal.R
Created February 17, 2014 16:38
Show what's in .Internal function
library("httr")
library("rjson")
internal <- function(fun){
names.c <- content( GET("https://raw2.github.com/wch/r-source/trunk/src/main/names.c") )
names.c <- strsplit( names.c, "\\n" )[[1L]]
rx <- sprintf('^[{]"%s"', fun )
match <- grep( rx, names.c)
if( length(match) != 1L ){