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(purrr)
library(github) # install_github("cscheid/rgithub")
library(dplyr)
library(stringr)
library(magrittr)
# Download issues ---------------------------------------------------------
ctx <- interactive.login("56b637a5baffac62cad9", "8e107541ae1791259e9987d544ca568633da2ebf")
issues1 <- get.repository.issues("hadley", "dplyr", per_page = 100)
@romainfrancois
romainfrancois / forbidden.c
Created September 22, 2014 10:02
get some forbidden C/R API fruits
#include <Rinternals.h>
#include <Rinterface.h>
extern void* R_GlobalContext ;
#define R_NO_REMAP
#define USE_RINTERNALS
#include <R.h>
#include <Rinternals.h>
```
ir <- structure( iris, class = c("foo", "data.frame") )
rbind.foo <- function(...) rbind.data.frame(...)
rbind(ir,iris)
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#ir Numeric,150 Numeric,150 Numeric,150 Numeric,150 factor,150
#iris Numeric,150 Numeric,150 Numeric,150 Numeric,150 factor,150
```
So apparently we get the same as :
@romainfrancois
romainfrancois / mario.R
Last active August 29, 2015 14:04
mario beep on OSX
# The code below will probably only work on Linux and requires VLC on the path.
library(beepr)
library(stringr)
play_vlc <- function(fname) {
system(paste("open -a vlc --args --no-loop --no-repeat --playlist-autostart --no-media-library", fname),
ignore.stdout = TRUE, ignore.stderr=TRUE,wait = FALSE)
}
# Plays the mario theme while expr is executing, plays the flag pole jingle when the execution have finished.
#include <Rcpp.h>
using namespace Rcpp ;
class abc {
public:
abc( SEXP x ) : data(x){}
inline operator SEXP() const {
return data ;
}
#!/usr/bin/R
# this script is poorly-written, so use at your own risk.
# ---------------------------------------------------------------
#
# THIS HAS A VERY GOOD CHANCE OF COMPLETELY DESTROYING YOUR REPO;
# ONLY RUN THIS ON A COPY OF THE REPO!!!
#
# ----------------------------------------------------------------
@romainfrancois
romainfrancois / README.md
Created May 22, 2014 09:46
Extending wrap in Rcpp11

Context

Extending wrap to custom classes has always been a struggle in Rcpp, and led to the split between RcppCommon.h and Rcpp.h, the idea being that you load a "minimal" subset of Rcpp, declare your class, declare that you are going to provide a specialization of wrap, load the rest of Rcpp (the meat), and finally define your specialization.

Let's consider this template class :

template <typename T>
class MyType {} ;
@romainfrancois
romainfrancois / benchmarks.md
Last active August 29, 2015 14:01
Compilation times

This little benchmark compares the times it take to compile a really simple Rcpp example (the example you get from RStudio when you do new C++ file) with Rcpp and Rcpp11.

require(microbenchmark)
compile_Rcpp <- function(){
  Rcpp::sourceCpp("/tmp/timesTwo.cpp", rebuild = TRUE )
}
compile_Rcpp11 <- function(){
  attributes::sourceCpp( "/tmp/timesTwo.cpp" )
}
@romainfrancois
romainfrancois / output.txt
Created May 11, 2014 17:22
log of installing Dirk's RcppRedis
romain@naxos ~/git/Rcpp11/Rcpp11 $ brew install hiredis
==> Downloading https://github.com/redis/hiredis/archive/v0.11.0.tar.gz
######################################################################## 100,0%
==> make install PREFIX=/usr/local/Cellar/hiredis/0.11.0
🍺 /usr/local/Cellar/hiredis/0.11.0: 11 files, 156K, built in 5 seconds
romain@naxos ~/git/Rcpp11/Rcpp11 $
romain@naxos ~/git/Rcpp11/Rcpp11 $ R
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
@romainfrancois
romainfrancois / README.md
Last active August 29, 2015 13:59
rev with Rcpp and Rcpp11