Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
R and C++. Past Present and Future.
Search
Romain
April 05, 2017
Technology
0
380
R and C++. Past Present and Future.
R and C++. Past Present and Future. Presented at the MilanoR meetup on 2017-04-05
Romain
April 05, 2017
Tweet
Share
Other Decks in Technology
See All in Technology
Compose Compiler Metricsを使った実践的なコードレビュー
tomorrowkey
1
220
元インフラエンジニアに成る / Human Resources to Human Relations
bobtani
4
890
本当のAWS基礎
toru_kubota
0
490
ServiceNow Knowledge Learning Rise up
manarobot
0
200
Meta Quest 3 で動く桜マシマシ WebXR アプリを IBM Cloud Code Engine と Babylon.js で作った話
1ftseabass
PRO
0
120
Janus
bkuhlmann
1
490
Google Cloud Next '24でブログを10本書いた方法と勉強会を沸かせた方法
yasumuusan
0
290
FrontDoorとWebAppsを組み合わせた際のリダイレクト処理の注意点
kenichirokimura
1
490
反実仮想機械学習とは何か
usaito
PRO
9
3.3k
JAWS-UG Bedrock Claude Night
yamahiro
3
540
Java EE/Jakarta EEの現状と将来―クラウドネイティブ時代にJava EEは対応できるのか?―
takakiyo
1
130
オーナーシップを持つ領域を明確にする
konifar
13
3.1k
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Product Roadmaps are Hard
iamctodd
44
9.7k
In The Pink: A Labor of Love
frogandcode
138
21k
What the flash - Photography Introduction
edds
64
11k
What's new in Ruby 2.0
geeforr
337
31k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
2
1.3k
Web development in the modern age
philhawksworth
202
10k
Become a Pro
speakerdeck
PRO
11
4.5k
The Pragmatic Product Professional
lauravandoore
25
5.8k
The Language of Interfaces
destraynor
151
23k
The Brand Is Dead. Long Live the Brand.
mthomps
49
28k
Robots, Beer and Maslow
schacon
PRO
155
7.9k
Transcript
R and C++ Past, Present and Future Romain François Consulting
Datactive
[email protected]
@romain_francois
None
None
None
Training / Development / Support @thinkR_fr
Rcpp
devtools::revdep( "Rcpp") ABCoptim AbsFilterGSEA acc accelerometry acebayes ACEt acrt AdaptiveSparsity
ADMMnet AhoCorasickTrie AHR alakazam algstat AlignStat ALKr alphabetr Amelia anytime apcluster arrApply ashr ASPBay aSPU attrCUSUM autovarCore BaBooN BacArena baitmet BalancedSampling BAMBI BAMMtools Barycenter BatchMap batman bayesAB BayesBD BayesComm bayesDP BayesFactor BayesianTools bayesImageS bayesm bayou bcp bcpa bcROCsurface BCSub bea.R beanz BEDMatrix benchr BeviMed beyondWhittle bfa bifactorial bife BIFIEsurvey biganalytics bigFastlm biglasso bigmemory BigQuic bigReg bigtabulate BigVAR bindrcpp bio3d Biocomb BIPOD biwavelet blackbox blockcluster blockmodels blockseg BLPestimatoR bmlm bnnSurvival BNSL bootTimeInference bridgesampling brms bsearchtools btb btf BTLLasso BTR BTYDplus BuyseTest bvarsv bWGR BWStest CARBayes CARBayesST catlearn ccaPP cccp ccdrAlgorithm cda CDF.PSIdekick CDM CFC cgAUC ChannelAttribution chopthin CIDnetworks CircularDDM cIRT cladoRcpp classifierplots classify cleanEHR clere climdex.pcic clogitboost clogitL1 clusrank ClusterR ClusterStability clusteval ClustMMDD ClustVarLV CMF CNull coala CoFRA collUtils combiter CompGLM ConConPiWiFun coneproj contoureR copCAR cord CorReg Countr Coxnet CoxPlus cpgen cpr cqrReg crawl creditr crmPack Crossover cstab ctmcd cubature CVR cxxfunplus cycleRtools Cyclops D3M darch dbmss dbscan ddalpha ddR DDRTree deepboost DeLorean densityClust DEploid DepthProc DescTools DetMCD DetR devtools dfcomb dfmta dfphase1 dfpk diagis DiffNet diffrprojects DiffusionRgqd DiffusionRimp DiffusionRjgqd diffusr dils dina disclapmix discretecdAlgorithm diversitree diveRsity divest dlib DLMtool DNAtools dnc dplyr drgee dslice DStree dtwclust dynamichazard dynsbm easyVerification EBMAforecast ECctmc ecp EditImputeCont eDMA eggCounts eive EloChoice EMbC emil emIRT energy EPGLM erah esaddle ESGtoolkit EstHer ETAS eulerr evolqg EWGoF exif extraDistr factorcpt FactoRizationMachines factorstochvol fastAdaboost FastBandChol fastcmh fasteraster fastGHQuad FastGP FastHCS fastHorseshoe fastJT fastM FastPCS FastRCS FBFsearch fbroc FCNN4R fdaMixed fdapace fdasrvf FDGcopulas FDRreg feather FeatureHashing ffstream FIACH fICA filesstrings FisHiCal FIT flam flan flars flexsurv flip flock FLSSS forecast forecastSNSTS forega forestFloor fourierin fourPNO fractional frailtyEM frailtySurv FRESA.CAD FRK fromo FSelectorRcpp FSInteract fst fugeR FunChisq Funclustering futureheatwaves fwsim gamreg gapfill GAS gaselect gaston GauPro gbp gcKrig GCPM GDINA gdm gdpc gdtools gee4 GEEaSPU geiger genie GENLIB GenomicTools geoCount geohash geojsonR GERGM ggdmc ggforce ggraph ggrepel GiRaF gjam gkmSVM glamlasso glcm GLMaSPU glmBfp glmgraph glmmsr GMCM Gmedian Gmisc gmum.r gmwm gMWT gogamer googleway GPareto gpuR GPvam gRain graphicalVAR graphkernels GraphKit graphql grattan gRbase gRim grove growcurves growfunctions GSE gsEasy gsynth GUILDS GUTS gwfa GWmodel GxM h5 hashmap haven hawkes hBayesDM HDPenReg hierarchicalSets hit hkevp HLMdiag hmi HSAR hsphase htdp htmltidy htmltools hts httpuv HUM humaniformat humarray hunspell hyperSpec hypervolume hyphenatr IAPWS95 iBATCGH IBHM ibm ibmcraftr iBST icamix ICAOD iccbeta icd icd9 icenReg icensmis icRSF ICtest ie2misc iemisc IHSEP iLaplace imager imagine immer imputeMulti inarmix inca indelmiss iNextPD inferr inline IntegratedMRF interflex ipft iprior iptools IRTpp IsingSampler isoph ISOpureR IsoSpecR iterpc JacobiEigen JAGUAR jiebaR jmcm jmotif joineRML joinXL JOUSBoost jqr JSM jtGWAS jwutil kamila kdecopula kdevine kergp kernDeepStackNet KernelKnn KernSmoothIRT kmc kmeans.ddR Kmisc KODAMA kohonen KoulMde l0ara LaF LambertW lamW LANDD Langevin largeVis LassoBacktracking lasvmR LatentREGpp lbfgs LBSPR lclGWAS lcopula lexRankr lfl lidR lifecontingencies lm.br lme4 lowmemtkmeans lpme lsbclust lsgl lucr ludic Luminescence MADPop mafs magick MAINT.Data ManifoldOptim mapview marked markophylo markovchain MAT matchingMarkets matchingR MatchItSE mateable MatrixCorrelation MatrixLDA MAVE maxent mbbefd mcemGLM mcga mcIRT mcmcse mcPAFit medfate MediaK MEGENA MESS metafolio MetaheuristicFPA meteoland mets mev mgm mice miceadds microclass microseq milr minimaxdesign minqa mirt mirtCAT miscF miscset MiSPU missDeaths MixAll MixedDataImpute mixedMem mixlink mixpack mixR mkde mlmc mlxR mmand ModelMetrics Morpho mousetrap move moveHMM moveWindSpeed mp Mposterior MPTinR mrfDepth mrgsolve MRS MSGARCH msgl MTS multdyn MultiBD multicool multinet MultivariateRandomForest mvabund MVB mvcluster mvnfast mwaved myTAI nabor NAM ndjson ndl NestedCategBayesImpute netcoh netdiffuseR NetRep NetSim NetworkInference neuroim ngspatial NHMM nmfgpu4R NNLM noncompliance nonlinearTseries NPBayesImpute NPflow nprobust nse odbc odeintr oem officer OjaNP olctools OneArmPhaseTwoStudy onlinePCA ontologySimilarity openair OpenImageR OpenMx openxlsx optimization optiSel optmatch opusminer orQA PAC packcircles pacotest padr PAFit palm pander PanelCount partialAR patternplot pcalg pcIRT pdftools pdp pdSpecEst PedCNV pedometrics penalized PenCoxFrail penMSM perccal PerMallows pgee.mixed ph2bayes ph2bye phangorn phonics phybreak phylobase phylocurve PhylogeneticEM phylosignal Pijavski pinbasic pirate plac planar planor PLMIX plogr plotSEMM plyr poisDoubleSamp polyfreqs polywog POUMM PoweR PP PPtreeViz prclust precrec PReMiuM primes ProbitSpatial pROC prodlim ProFit ProNet propagate prophet propr prospectr protolite prototest protViz pryr psd psgp purrr pvar PWD pystr qrencoder QRM quadrupen qualpalr quanteda quantspec QuantTools queuecomputer qVarSel qwraps2 radiomics rags2ridges ragt2ridges ramcmc randomUniformForest ranger Rankcluster rankdist raptr raster Rblpapi Rborist Rcereal Rclusterpp RcppAnnoy RcppAPT RcppArmadillo RcppBDT RcppBlaze RcppCCTZ RcppClassic RcppClassicExamples RcppCNPy RcppDE RcppDL RcppEigen RcppExamples RcppFaddeeva RcppGetconf RcppGSL RcppHMM RcppHoney RcppMLPACK RcppNumerical RcppOctave RcppParallel RcppProgress RcppRedis RcppRoll RcppShark RcppSMC RcppStreams RcppTOML RcppXts RcppZiggurat rcss rdist Rdtq readr readstata13 readxl RealVAMS recexcavAAR recmap reconstructr recosystem redist rEDM regsem ReIns relSim rem remote ReorderCluster repolr resemble reshape2 reticulate revealedPrefs rexpokit Rfast rflann rforensicbatwing rFTRLProximal rgam rgeolocate RI2by2 RInside Rip46 ripa rIsing riskRegression rivr rkvo Rlabkey rlas Rlda Rlibeemd RLRsim RLumModel Rmalschains rmgarch Rmixmod RmixmodCombi rmumps rncl RNifti RNiftyReg robCompositions robets robustgam RobustGaSP robustHD robustlmm robustreg rococo roll rollply rootWishart rotations RoughSets roxygen2 rpg Rphylopars rpms rPref RProtoBuf RPtests RQuantLib rrr RSNNS RSNPset Rsomoclu RSpectra RSQLite RSSL rstan rstanarm RStoolbox rstpm2 rtext rtk rtkore Rtsne Ruchardet rucrdtw rugarch Rvcg rvg Rvoterdistance RVowpalWabbit rwfec rwirelesscom Ryacas s2 saeRobust SAMM satellite saturnin sbart sbfc sBIC sbmSDP sbrl SBSA scales SciencesPo scorer scoringRules scrm scrypt scvxclustr sdcMicro sdcTable secure SEERaBomb segmag seismicRoll SelvarMix semver seqHMM sequences sf sgd sglOptim sharpeRratio signalHsmm simFrame simmer simPop SimReg simstudy sirt sitmo skm slfm SLOPE smam SmartSVA SMMA smoof smooth SnakeCharmR snipEM snowboot snplist SocialNetworks SOD SpaCCr spacodiR spaMM SparseFactorAnalysis sparseHessianFD sparseLTSEigen sparsepp sparsereg spass spatgraphs SpatialEpi SpatialTools SpaTimeClus SpatMCA SpatPCA spBayesSurv spduration SpecsVerification spectral sppmix spray spsann SSL starma staTools stdvectors steadyICA StepwiseTest StereoMorph stlplus stm StMoSim stochvol stocks stosim stplanr stpm strat strataG stream stremr striprtf strum supc SuperRanker survAccuracyMeasures surveillance surveybootstrap survSNP svglite SVMMatch synchronicity synlik synthACS systemicrisk tagcloud TAM TAQMNGR TauStar tbart tcR TDA tensorBSS termstrc TESS tesseract testforDEP text2vec textmineR textreg textreuse textTinyR TFMPvalue tibble tidyr tidyxl timma TLMoments tm tmg tmlenet tnam tokenizers TransferEntropy TreeBUGS treeclim treeplyr treescape treespace triebeard trustOptim tsBSS tvd tweenr UncerIn2 unmarked unsystation urltools V8 validatejsonr valr valuer varband varbvs VarSelLCM vcfR vdiffr velox VideoComparison VIM vita VNM waffect walkr wand wCorr webreadr wicket wingui Wmisc wordcloud wordspace wrswoR wsrf XBRL xml2 xslt xyz yakmoR yCrypticRNAs yuima zic ziphsmm 1001 9.63 %
devtools::revdep( "Rcpp", recursive = TRUE) 7812 75.23 %
*.h 95 235 *.cpp 5 698 100 933 *.R 3
177
motivation
int add( int a, int b ){ return a +
b ; } > add( 40, 2 ) [1] 42
past C/R API
#include <R.h> #include <Rinternals.h> int add( int a, int b
){ return a + b ; } SEXP add_c( SEXP a_, SEXP b_ ){ int a = INTEGER(a_)[0], b = INTEGER(b_)[0] ; int res = add( a, b ) ; SEXP result = PROTECT(allocVector(INTSXP, 1) ) ; INTEGER(result)[0] = res ; UNPROTECT(1) ; return result ; }
add <- function(a, b){ .Call( "add_c", a, b ) }
> add( 40, 2 ) Error in add(33, 9) : INTEGER() can only be applied to a 'integer', not a 'double' > add( 40L, 2L ) [1] 42
add <- function(a, b){ .Call( "add_c", as.integer(a), as.integer(b) ) }
> add( 40, 2 ) [1] 42 > add( 40L, 2L ) [1] 42
Tools • SEXP • INTEGER • PROTECT • allocVector •
INTSXP • UNPROTECT • .Call • as.integer
present Rcpp
#include <Rcpp.h> // [[Rcpp::export]] int add( int a, int b
){ return a + b ; } > add( 17L, 25L ) [1] 42 > add( 17, 25 ) [1] 42
example
None
! weighted_mean_1 <- function(x, w) { total <- 0 total_w
<- 0 for (i in seq_along(x)) { total <- total + x[i] * w[i] total_w <- total_w + w[i] } total / total_w }
" weighted_mean_2 <- function(x, w) { sum(x*w) / sum(w) }
# weighted.mean
$ #include <Rcpp.h> using namespace Rcpp ; // [[Rcpp::export]] double
weighted_mean_cpp( NumericVector x, NumericVector w){ int n = x.size() ; double total = 0.0 ; double total_w = 0.0 ; for( int i=0; i<n; i++){ total += x[i] * w[i] ; total_w += w[i] ; } return total / total_w ; }
None
None
future ?
Rcpp is like usb …
… but we want usb-c
Rcpp is too huge and not modular
Rcpp n + 2 core sugar modules core modules Rcpp
n +1 core sugar modules core modules Rcpp n core sugar modules core modules % mypkg ' ✔ $ )
proposal
NumericVector IntegerVector CharacterVector Function sugar modules … IntegerVector CharacterVector Function
sugar NumericVector core core modules … core pkg1 pkg2 core pkg3 core CharacterVector IntegerVector NumericVector
' ✔ $ ) ✔ ✔
Pros • Smaller • Faster • Robust • Controlled updates
Cons • More copies of code base • Maybe more testing
None
http://bit.ly/milanorcpp