SlideShare une entreprise Scribd logo
1  sur  53
Extend R with C!!!
   2009/11/22 id:mickey24
id: mickey24 (@mickey24)
id: mickey24 (@mickey24)
• Tsukuba.R#4
 •   R    Brainf*ck
• Tsukuba.R#4
 •   R       Brainf*ck


• Tsukuba.R#5
 •   Animation with R
C   R
•
•
C   R
C    R
•C       R
C        R
•C           R

•C   R               C
                 R
Motivation
Motivation
1.
Motivation
1.
     •
Motivation
1.
     •
     •          C   R                     (40   50   )   www
         - Seeking for my unique color.
         http://d.hatena.ne.jp/syou6162/20090117/1232120983
Motivation
1.
     •
     •          C   R                     (40   50   )   www
         - Seeking for my unique color.
         http://d.hatena.ne.jp/syou6162/20090117/1232120983

2. R           C
#include <R.h>
#include <Rinternals.h>


SEXP test(SEXP exp) {
    ...
}
C     R

// integer
int n = INTEGER(exp)[0];


// string
PROTECT(exp = AS_CHARACTER(exp));
char* str = R_alloc(strlen(CHAR(
  STRING_ELT(exp, 0))), sizeof(char));
strcpy(str, CHAR(STRING_ELT(exp, 0)));
...
UNPROTECT(1)
C     R

// integer
SEXP exp_int;
PROTECT(exp_int = NEW_INTEGER(1));
int* pi = INTEGER_POINTER(exp_int);
pi[0] = 24;
...
UNPROTECT(1);
return exp_int;
$ R CMD SHLIB test.c
$ R CMD SHLIB test.c

•   test.so
$ R CMD SHLIB test.c

•   test.so

•   R               R
$ R CMD SHLIB test.c

•   test.so

•   R                  R

•   Makefile Makevars
R            C
dyn.load("test.so")

test <- function(n) {
  .Call("test", integer(n))
}

test(24)



    Writing R Extensions
    http://cran.r-project.org/doc/contrib/manuals-jp/R-exts.jp.pdf
•
•
•C   R
•C   R

•        C
         R
•C   R

•          C
           R

•        6162
OpenCV
OpenCV
•
OpenCV
•
• BSD
OpenCV
•
• BSD
• C C++   Python
OpenCV
•
• BSD
• C C++   Python


•
…
…
…




    …
•
•
•C   R
•
•C   R


•
•   C   R                                - Seeking for my unique color.
    http://d.hatena.ne.jp/syou6162/20090117/1232125870


•   Writing R Extensions
    http://cran.r-project.org/doc/contrib/manuals-jp/R-exts.jp.pdf
Extend R with C!!!

Contenu connexe

Similaire à Extend R with C!!!

Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Hiroki Mizuno
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in Rmickey24
 
tool of character level of segmentation
tool of character level of segmentationtool of character level of segmentation
tool of character level of segmentationHao Wei He
 
純粋関数型データ構造
純粋関数型データ構造純粋関数型データ構造
純粋関数型データ構造wat-aro
 
Py "Baseball" Data入門〜サービス(と野球)を支えるデータ分析基盤 #monotarotech
Py "Baseball" Data入門〜サービス(と野球)を支えるデータ分析基盤 #monotarotechPy "Baseball" Data入門〜サービス(と野球)を支えるデータ分析基盤 #monotarotech
Py "Baseball" Data入門〜サービス(と野球)を支えるデータ分析基盤 #monotarotechShinichi Nakagawa
 
Fast track to getting started with DSE Max @ ING
Fast track to getting started with DSE Max @ INGFast track to getting started with DSE Max @ ING
Fast track to getting started with DSE Max @ INGDuyhai Doan
 
A Plan towards Ruby 3 Types
A Plan towards Ruby 3 TypesA Plan towards Ruby 3 Types
A Plan towards Ruby 3 Typesmametter
 
Data Manipulation Using R (& dplyr)
Data Manipulation Using R (& dplyr)Data Manipulation Using R (& dplyr)
Data Manipulation Using R (& dplyr)Ram Narasimhan
 
Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - BasicWei-Yuan Chang
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...Paul Leclercq
 
Exploring cypher with graph gists
Exploring cypher with graph gistsExploring cypher with graph gists
Exploring cypher with graph gistsLuanne Misquitta
 
Kubernetes で実現するインフラ自動構築パイプライン
Kubernetes で実現するインフラ自動構築パイプラインKubernetes で実現するインフラ自動構築パイプライン
Kubernetes で実現するインフラ自動構築パイプラインYusuke Nojima
 
Aprils fool 2014
Aprils fool 2014Aprils fool 2014
Aprils fool 2014bijan_
 

Similaire à Extend R with C!!! (17)

Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in R
 
tool of character level of segmentation
tool of character level of segmentationtool of character level of segmentation
tool of character level of segmentation
 
純粋関数型データ構造
純粋関数型データ構造純粋関数型データ構造
純粋関数型データ構造
 
Py "Baseball" Data入門〜サービス(と野球)を支えるデータ分析基盤 #monotarotech
Py "Baseball" Data入門〜サービス(と野球)を支えるデータ分析基盤 #monotarotechPy "Baseball" Data入門〜サービス(と野球)を支えるデータ分析基盤 #monotarotech
Py "Baseball" Data入門〜サービス(と野球)を支えるデータ分析基盤 #monotarotech
 
Tokyo r18
Tokyo r18Tokyo r18
Tokyo r18
 
Fast track to getting started with DSE Max @ ING
Fast track to getting started with DSE Max @ INGFast track to getting started with DSE Max @ ING
Fast track to getting started with DSE Max @ ING
 
A Plan towards Ruby 3 Types
A Plan towards Ruby 3 TypesA Plan towards Ruby 3 Types
A Plan towards Ruby 3 Types
 
Data Manipulation Using R (& dplyr)
Data Manipulation Using R (& dplyr)Data Manipulation Using R (& dplyr)
Data Manipulation Using R (& dplyr)
 
Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - Basic
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
 
Exploring cypher with graph gists
Exploring cypher with graph gistsExploring cypher with graph gists
Exploring cypher with graph gists
 
Rug hogan-10-03-2012
Rug hogan-10-03-2012Rug hogan-10-03-2012
Rug hogan-10-03-2012
 
Kubernetes で実現するインフラ自動構築パイプライン
Kubernetes で実現するインフラ自動構築パイプラインKubernetes で実現するインフラ自動構築パイプライン
Kubernetes で実現するインフラ自動構築パイプライン
 
Aprils fool 2014
Aprils fool 2014Aprils fool 2014
Aprils fool 2014
 
Lec-1c.pdf
Lec-1c.pdfLec-1c.pdf
Lec-1c.pdf
 

Extend R with C!!!