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 / 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.
```
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 / 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>
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 / README.md
Last active December 23, 2015 17:59
USE_RINTERNALS and Rcpp
$ R CMD SHLIB size.c
$ Rscript -e "dyn.load('size.so'); siz <- function(.) .Call( 'siz', .) ; siz(1:10); siz(siz); siz(letters) "
[1] 88
[1] 600
[1] 1496
@romainfrancois
romainfrancois / NA_Proxy.h
Last active December 23, 2015 21:59
A new approach of NA handling
// Copyright (C) 2013 Romain Francois
//
// This file is part of Rcpp11.
//
// Rcpp11 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Rcpp11 is distributed in the hope that it will be useful, but
@romainfrancois
romainfrancois / dots.R
Last active December 24, 2015 09:59
Passing down unevaluated parameters
require(Rcpp)
sourceCpp( "dots.cpp" )
x <- 1
f <- function(...) {
x <- 2
g(..., b = x)
}
g <- function(...) {
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector rowApply0(NumericMatrix& x, const Function& FUN)
{
int n = x.nrow();
NumericVector result = no_init(n);
for (int r = 0; r < n; r++) {
@romainfrancois
romainfrancois / gist:6981372
Last active December 25, 2015 13:09
Reading the internal function table
#include <Rcpp.h>
using namespace Rcpp;
typedef SEXP (*CCODE)(SEXP, SEXP, SEXP, SEXP);
/* Information for Deparsing Expressions */
typedef enum {
PP_INVALID = 0,
PP_ASSIGN = 1,
PP_ASSIGN2 = 2,
@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_){}