SlideShare a Scribd company logo
The Compatibility Challenge:
Examining R and Developing TERR
Michael Sannella (msannell@tibco.com)
TIBCO Spotfire
http://spotfire.tibco.com
These slides contain all the content from the
useR!2014 poster with the same name
What is TERR?
• TERR: TIBCO® Enterprise Runtime for R
• A commercial R-compatible statistics engine.
• The latest in a family of scripting engines.
• S, S-PLUS®, R, TERR
• Embedded in Spotfire®
• Provides R scripting, powers analytic tools.
• Free Developer's Edition available.
• Commercially available for custom integration.
2
Why R Compatibility?
• We developed TERR as a completely independent
engine, without looking at R sources or
documentation.
• However, we want TERR to be able to load and run
R packages from CRAN and other repositories, so
TERR must be compatible with R.
• Many CRAN packages work with TERR without change.
• Some CRAN packages can be made to work with TERR if
we rebuild them, without changing any of their code.
• Some (hopefully few) CRAN packages require code
changes to make them work under TERR.
3
How to Achieve R Compatibility?
• Our approach: Examine R’s behavior, write unit
tests, and make TERR pass these tests.
• R compatibility is a moving target: As R and the
CRAN packages change over time, we must update
TERR to follow.
• R Wrinkles: While tracking down TERR
incompatibility issues, we uncovered some
interesting R behavior.
• In some cases, we decided not to make TERR
completely compatible with R.
4
Developing Compatibility Using
Key Packages
• For some elements of R, a good way to develop
compatibility was to focus on a key package or
application that exercises certain functionality.
• Key package: The CRAN Matrix package
• Matrix fully exercised the S4 object system.
• Getting the Matrix tests working gave us confidence that we
had a compatible implementation of S4.
• Key application: The RStudio GUI
• RStudio exercised the R engine entries used to embed R
within an application.
• RStudio exercised source-code access via the “srcref”
attribute on parsed expressions and functions.
• RStudio exercised the trace, browser functions used for
breakpoints and single-stepping.
5
R Wrinkles: Character Encoding
• TERR/R Incompatibility: R uses the "unknown"
character encoding for most strings, whereas TERR
uses the UTF-8 encoding by default.
• R inconsistency: Character encoding of string
constants.
R-3.0.1/Linux
> Encoding(c('abcxC4xyz', 'abcu00C4xyz'))
[1] "unknown" "UTF-8"
R-3.0.1/Windows (and TERR 2.6)
> Encoding(c('abcxC4xyz', 'abcu00C4xyz'))
[1] "latin1" "UTF-8"
6
R Wrinkles: Character Encoding (2)
• R inconsistency: The R/Windows parser doesn't
accept many UTF-8 chars in names.
R 3.1.0 Linux (and TERR 2.6):
> typeof(parse(text="au30A4")[[1]])
[1] "symbol"
R 3.1.0 Windows:
> typeof(parse(text="au30A4")[[1]])
Error in parse(text = "a<U+30A4>") :
<text>:1:7: unexpected symbol
1: a<U+30A4
^
7
R Wrinkles: Non-Local Returns
• Initially, we had problems using TERR in RStudio,
which executes functions with the following form:
function() {
tryCatch(return(someCalc()),
error=function(e) return("err"))}
• The first argument to tryCatch is evaluated in a
promise, but it can include a “non-local” return that
unwinds the stack to the function where “return”
appears.
8
R Wrinkles: Non-Local Returns (2)
• Consider the following code:
yy <- function(expr, n) {
cat("yy: n=", n, "n")
if (n>1) {
yy(expr, n-1)
} else {
expr
}
"yyret"
}
zz <- function(n) {
yy(return(n), n)
"zzret"
}
• When the expression expr is finally
evaluated in yy, it unwinds multiple
calls to yy, and returns from the
outer function zz:
> zz(3)
yy: n= 3
yy: n= 2
yy: n= 1
[1] 3
>
9
Compatibility Challenge: R’s C API
• Many CRAN packages contain C code calling into the R
engine via C entries (the “Rapi” API).
• We implement Rapi entries in TERR as we find CRAN
packages that need them.
• Problem: the USE_RINTERNALS macro
• If USE_RINTERNALS is defined, some R macros directly access
R object structures, instead of calling Rapi entries.
• This may improve performance for some code
(but this is not a panacea).
• This won't work with TERR, unless we make the TERR object
structure identical to the R object structure.
• Solution: Can gain compatibility for some packages by
rebuilding the package without USE_RINTERNALS
defined.
10
Compatibility Challenge: Packages
Including Base R Code
• Symptom: Trying to run Matrix code, we saw an
unexpected call to .Internal, though it didn’t appear in
the Matrix sources:
> checkMatrix(A)
Error in .Internal:
unimplemented .Internal function: drop
• Reason: S4 setGeneric can incorporate base function
definitions into a generic default method.
• Matrix defines methods for drop, which creates a generic
with base::drop as the default
• Solution: When TERR loads a package with an S4
default method from a system library (base, stats,
graphics, utils), it substitutes the TERR function from
that library.
11
Compatibility Challenge: The
smoothEnds Problem
• Symptom: In the IRanges package, the R system function
stats::smoothEnds works with an IRanges Rle object:
> x <- Rle((-4:4)^2)
> options(dropRle = TRUE)
> stats::smoothEnds(x)
numeric-Rle of length 9 with 9 runs
Lengths: 1 1 1 1 1 1 1 1 1
Values : 16 9 4 1 0 1 4 9 16
• However, this doesn't work in TERR:
> x <- Rle((-4:4)^2)
> options(dropRle = TRUE)
> stats::smoothEnds(x)
Error: 'y' must be numeric
12
Compatibility Challenge: The
smoothEnds Problem (2)
• Reason:
• TERR implements stats::smoothEnds in native C code.
• Most likely, R implements it as R-language code, calling
other arithmetic operators with methods defined for Rle
objects.
• Solution:
• Rewrite TERR’s version of stats::smoothEnds as R-
language code.
• Deeper issue:
• A TERR algorithm has to call the same methods as R, if
they can be redefined for particular object classes.
13
For More Information
• Drop by the TIBCO booth.
• Attend our talks:
• Louis Bajuk-Yorgan: “Deploying R into Business Intelligence and
Real-time Applications”
• (Business track, Session 5, Wednesday 16:00)
• Stephen Kaluzny: “Software Testing and the R Language”
• (Business track, Session 6, Thursday 10:00)
• Spotfire and TERR:
• http://spotfire.tibco.com/terr
• TERR Developer’s Edition:
• http://www.tibcommunity.com/community/products/analytics/terr
• http://tap.tibco.com/
• https://docs.tibco.com/products/tibco-enterprise-runtime-for-r
14

More Related Content

What's hot

0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
Maxim Kharchenko
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programming
newmedio
 
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Bhasker Kode
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you Begin
Sam Bowne
 
Logical Time
Logical TimeLogical Time
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
Scala Italy
 
Java 8 stream and c# 3.5
Java 8 stream and c# 3.5Java 8 stream and c# 3.5
Java 8 stream and c# 3.5
Quang Trần Duy
 
Building APIs with Kotlin and Spark
Building APIs with Kotlin and SparkBuilding APIs with Kotlin and Spark
Building APIs with Kotlin and Spark
Nordic APIs
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxCNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
Sam Bowne
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeCNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
Sam Bowne
 
Migrating Apache Spark ML Jobs to Spark + Tensorflow on Kubeflow
Migrating Apache Spark ML Jobs to Spark + Tensorflow on KubeflowMigrating Apache Spark ML Jobs to Spark + Tensorflow on Kubeflow
Migrating Apache Spark ML Jobs to Spark + Tensorflow on Kubeflow
Databricks
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
Maxim Kharchenko
 
Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full story
José Paumard
 
Return Oriented Programming
Return Oriented ProgrammingReturn Oriented Programming
Return Oriented Programming
UTD Computer Security Group
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
Knoldus Inc.
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
Jordan Parmer
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
Sam Bowne
 
CNIT 127: Ch 4: Introduction to format string bugs
CNIT 127: Ch 4: Introduction to format string bugsCNIT 127: Ch 4: Introduction to format string bugs
CNIT 127: Ch 4: Introduction to format string bugs
Sam Bowne
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
datamantra
 
06 uml-component
06 uml-component06 uml-component
06 uml-component
ATCUTA BHAVANI SIRIKI
 

What's hot (20)

0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programming
 
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you Begin
 
Logical Time
Logical TimeLogical Time
Logical Time
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 
Java 8 stream and c# 3.5
Java 8 stream and c# 3.5Java 8 stream and c# 3.5
Java 8 stream and c# 3.5
 
Building APIs with Kotlin and Spark
Building APIs with Kotlin and SparkBuilding APIs with Kotlin and Spark
Building APIs with Kotlin and Spark
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxCNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeCNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
 
Migrating Apache Spark ML Jobs to Spark + Tensorflow on Kubeflow
Migrating Apache Spark ML Jobs to Spark + Tensorflow on KubeflowMigrating Apache Spark ML Jobs to Spark + Tensorflow on Kubeflow
Migrating Apache Spark ML Jobs to Spark + Tensorflow on Kubeflow
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
 
Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full story
 
Return Oriented Programming
Return Oriented ProgrammingReturn Oriented Programming
Return Oriented Programming
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 
CNIT 127: Ch 4: Introduction to format string bugs
CNIT 127: Ch 4: Introduction to format string bugsCNIT 127: Ch 4: Introduction to format string bugs
CNIT 127: Ch 4: Introduction to format string bugs
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
06 uml-component
06 uml-component06 uml-component
06 uml-component
 

Similar to The Compatibility Challenge:Examining R and Developing TERR

محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
مركز البحوث الأقسام العلمية
 
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
مركز البحوث الأقسام العلمية
 
Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga
DTU - Technical University of Denmark
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
Ralf Gommers
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with R
Martin Jung
 
Introduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics ResearchersIntroduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics Researchers
Vitomir Kovanovic
 
R Programming Language
R Programming LanguageR Programming Language
R Programming Language
NareshKarela1
 
Lecture1
Lecture1Lecture1
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
James Long
 
Introduction to statistical software R
Introduction to statistical software RIntroduction to statistical software R
Introduction to statistical software R
Paola Pozzolo - La tua statistica
 
Sannella use r2013-terr-memory-management
Sannella use r2013-terr-memory-managementSannella use r2013-terr-memory-management
Sannella use r2013-terr-memory-management
Lou Bajuk
 
2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer
tirlukachaitanya
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
KabilaArun
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
DrGSakthiGovindaraju
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
attalurilalitha
 
R Programming - part 1.pdf
R Programming - part 1.pdfR Programming - part 1.pdf
R Programming - part 1.pdf
RohanBorgalli
 
R basics for MBA Students[1].pptx
R basics for MBA Students[1].pptxR basics for MBA Students[1].pptx
R basics for MBA Students[1].pptx
rajalakshmi5921
 
R Jobs on the Cloud
R Jobs on the CloudR Jobs on the Cloud
R Jobs on the Cloud
John Doxaras
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
senthil0809
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
Ajay Ohri
 

Similar to The Compatibility Challenge:Examining R and Developing TERR (20)

محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with R
 
Introduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics ResearchersIntroduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics Researchers
 
R Programming Language
R Programming LanguageR Programming Language
R Programming Language
 
Lecture1
Lecture1Lecture1
Lecture1
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
 
Introduction to statistical software R
Introduction to statistical software RIntroduction to statistical software R
Introduction to statistical software R
 
Sannella use r2013-terr-memory-management
Sannella use r2013-terr-memory-managementSannella use r2013-terr-memory-management
Sannella use r2013-terr-memory-management
 
2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R Programming - part 1.pdf
R Programming - part 1.pdfR Programming - part 1.pdf
R Programming - part 1.pdf
 
R basics for MBA Students[1].pptx
R basics for MBA Students[1].pptxR basics for MBA Students[1].pptx
R basics for MBA Students[1].pptx
 
R Jobs on the Cloud
R Jobs on the CloudR Jobs on the Cloud
R Jobs on the Cloud
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
 

More from Lou Bajuk

R Consortium update for EARL Boston Oct 2017
R Consortium update for EARL Boston Oct 2017R Consortium update for EARL Boston Oct 2017
R Consortium update for EARL Boston Oct 2017
Lou Bajuk
 
Reusing and Managing R models in an Enterprise
Reusing and Managing  R models in an EnterpriseReusing and Managing  R models in an Enterprise
Reusing and Managing R models in an Enterprise
Lou Bajuk
 
R consortium update EARL London Sept 2017
R consortium update EARL London Sept 2017R consortium update EARL London Sept 2017
R consortium update EARL London Sept 2017
Lou Bajuk
 
Making Data Science accessible to a wider audience
Making Data Science accessible to a wider audienceMaking Data Science accessible to a wider audience
Making Data Science accessible to a wider audience
Lou Bajuk
 
R Consortium Update for EARL June 2017
R Consortium Update for EARL June 2017R Consortium Update for EARL June 2017
R Consortium Update for EARL June 2017
Lou Bajuk
 
Streaming analytics overview for R
Streaming analytics overview for RStreaming analytics overview for R
Streaming analytics overview for R
Lou Bajuk
 
Tibco streaming analytics overview and roadmap
Tibco streaming analytics overview and roadmapTibco streaming analytics overview and roadmap
Tibco streaming analytics overview and roadmap
Lou Bajuk
 
Embracing data science for smarter analytics apps
Embracing data science for smarter analytics appsEmbracing data science for smarter analytics apps
Embracing data science for smarter analytics apps
Lou Bajuk
 
EARL Sept 2016 R consortium
EARL Sept 2016 R consortiumEARL Sept 2016 R consortium
EARL Sept 2016 R consortium
Lou Bajuk
 
R in BI and Streaming Applications for useR 2016
R in BI and Streaming Applications for useR 2016R in BI and Streaming Applications for useR 2016
R in BI and Streaming Applications for useR 2016
Lou Bajuk
 
Applying the R Language to BI and Real Time Applications
Applying the R Language to BI and Real Time ApplicationsApplying the R Language to BI and Real Time Applications
Applying the R Language to BI and Real Time Applications
Lou Bajuk
 
Applying R in BI and Real Time applications EARL London 2015
Applying R in BI and Real Time applications EARL London 2015Applying R in BI and Real Time applications EARL London 2015
Applying R in BI and Real Time applications EARL London 2015
Lou Bajuk
 
Extending the R language to BI and Real-time Applications JSM 2015
Extending the R language to BI and Real-time Applications JSM 2015Extending the R language to BI and Real-time Applications JSM 2015
Extending the R language to BI and Real-time Applications JSM 2015
Lou Bajuk
 
Using the R Language in BI and Real Time Applications (useR 2015)
Using the R Language in BI and Real Time Applications (useR 2015)Using the R Language in BI and Real Time Applications (useR 2015)
Using the R Language in BI and Real Time Applications (useR 2015)
Lou Bajuk
 
Real time applications using the R Language
Real time applications using the R LanguageReal time applications using the R Language
Real time applications using the R Language
Lou Bajuk
 
The Importance of an Analytics Platform
The Importance of an Analytics PlatformThe Importance of an Analytics Platform
The Importance of an Analytics Platform
Lou Bajuk
 
TERR in BI and Real Time applications
TERR in BI and Real Time applicationsTERR in BI and Real Time applications
TERR in BI and Real Time applications
Lou Bajuk
 
Software Testing and the R language
Software Testing and the R languageSoftware Testing and the R language
Software Testing and the R language
Lou Bajuk
 
Deploying R in BI and Real time Applications
Deploying R in BI and Real time ApplicationsDeploying R in BI and Real time Applications
Deploying R in BI and Real time Applications
Lou Bajuk
 
Extending the Reach of R to the Enterprise with TERR and Spotfire
Extending the Reach of R to the Enterprise with TERR and SpotfireExtending the Reach of R to the Enterprise with TERR and Spotfire
Extending the Reach of R to the Enterprise with TERR and Spotfire
Lou Bajuk
 

More from Lou Bajuk (20)

R Consortium update for EARL Boston Oct 2017
R Consortium update for EARL Boston Oct 2017R Consortium update for EARL Boston Oct 2017
R Consortium update for EARL Boston Oct 2017
 
Reusing and Managing R models in an Enterprise
Reusing and Managing  R models in an EnterpriseReusing and Managing  R models in an Enterprise
Reusing and Managing R models in an Enterprise
 
R consortium update EARL London Sept 2017
R consortium update EARL London Sept 2017R consortium update EARL London Sept 2017
R consortium update EARL London Sept 2017
 
Making Data Science accessible to a wider audience
Making Data Science accessible to a wider audienceMaking Data Science accessible to a wider audience
Making Data Science accessible to a wider audience
 
R Consortium Update for EARL June 2017
R Consortium Update for EARL June 2017R Consortium Update for EARL June 2017
R Consortium Update for EARL June 2017
 
Streaming analytics overview for R
Streaming analytics overview for RStreaming analytics overview for R
Streaming analytics overview for R
 
Tibco streaming analytics overview and roadmap
Tibco streaming analytics overview and roadmapTibco streaming analytics overview and roadmap
Tibco streaming analytics overview and roadmap
 
Embracing data science for smarter analytics apps
Embracing data science for smarter analytics appsEmbracing data science for smarter analytics apps
Embracing data science for smarter analytics apps
 
EARL Sept 2016 R consortium
EARL Sept 2016 R consortiumEARL Sept 2016 R consortium
EARL Sept 2016 R consortium
 
R in BI and Streaming Applications for useR 2016
R in BI and Streaming Applications for useR 2016R in BI and Streaming Applications for useR 2016
R in BI and Streaming Applications for useR 2016
 
Applying the R Language to BI and Real Time Applications
Applying the R Language to BI and Real Time ApplicationsApplying the R Language to BI and Real Time Applications
Applying the R Language to BI and Real Time Applications
 
Applying R in BI and Real Time applications EARL London 2015
Applying R in BI and Real Time applications EARL London 2015Applying R in BI and Real Time applications EARL London 2015
Applying R in BI and Real Time applications EARL London 2015
 
Extending the R language to BI and Real-time Applications JSM 2015
Extending the R language to BI and Real-time Applications JSM 2015Extending the R language to BI and Real-time Applications JSM 2015
Extending the R language to BI and Real-time Applications JSM 2015
 
Using the R Language in BI and Real Time Applications (useR 2015)
Using the R Language in BI and Real Time Applications (useR 2015)Using the R Language in BI and Real Time Applications (useR 2015)
Using the R Language in BI and Real Time Applications (useR 2015)
 
Real time applications using the R Language
Real time applications using the R LanguageReal time applications using the R Language
Real time applications using the R Language
 
The Importance of an Analytics Platform
The Importance of an Analytics PlatformThe Importance of an Analytics Platform
The Importance of an Analytics Platform
 
TERR in BI and Real Time applications
TERR in BI and Real Time applicationsTERR in BI and Real Time applications
TERR in BI and Real Time applications
 
Software Testing and the R language
Software Testing and the R languageSoftware Testing and the R language
Software Testing and the R language
 
Deploying R in BI and Real time Applications
Deploying R in BI and Real time ApplicationsDeploying R in BI and Real time Applications
Deploying R in BI and Real time Applications
 
Extending the Reach of R to the Enterprise with TERR and Spotfire
Extending the Reach of R to the Enterprise with TERR and SpotfireExtending the Reach of R to the Enterprise with TERR and Spotfire
Extending the Reach of R to the Enterprise with TERR and Spotfire
 

Recently uploaded

快速办理(PU毕业证书)普渡大学毕业证文凭证书一模一样
快速办理(PU毕业证书)普渡大学毕业证文凭证书一模一样快速办理(PU毕业证书)普渡大学毕业证文凭证书一模一样
快速办理(PU毕业证书)普渡大学毕业证文凭证书一模一样
cfk7atz3
 
A Free eBook ~ Valuable LIFE Lessons to Learn ( 5 Sets of Presentations)...
A Free eBook ~ Valuable LIFE Lessons    to Learn   ( 5 Sets of Presentations)...A Free eBook ~ Valuable LIFE Lessons    to Learn   ( 5 Sets of Presentations)...
A Free eBook ~ Valuable LIFE Lessons to Learn ( 5 Sets of Presentations)...
OH TEIK BIN
 
2. The Book of Psalms: Recognition of the kingship and sovereignty of God
2. The Book of Psalms: Recognition of the kingship and sovereignty of God2. The Book of Psalms: Recognition of the kingship and sovereignty of God
2. The Book of Psalms: Recognition of the kingship and sovereignty of God
COACH International Ministries
 
yadadri temple history seva's list and timings
yadadri temple history seva's list and  timingsyadadri temple history seva's list and  timings
yadadri temple history seva's list and timings
knav9398
 
The_Chronological_Life_of_Christ_Part_104_Repentance_and_Restoration
The_Chronological_Life_of_Christ_Part_104_Repentance_and_RestorationThe_Chronological_Life_of_Christ_Part_104_Repentance_and_Restoration
The_Chronological_Life_of_Christ_Part_104_Repentance_and_Restoration
Network Bible Fellowship
 
Why is this So? ~ Do Seek to KNOW (English & Chinese).pptx
Why is this So? ~ Do Seek to KNOW (English & Chinese).pptxWhy is this So? ~ Do Seek to KNOW (English & Chinese).pptx
Why is this So? ~ Do Seek to KNOW (English & Chinese).pptx
OH TEIK BIN
 
The Hope of Salvation - Jude 1:24-25 - Message
The Hope of Salvation - Jude 1:24-25 - MessageThe Hope of Salvation - Jude 1:24-25 - Message
The Hope of Salvation - Jude 1:24-25 - Message
Cole Hartman
 
1. The Book of Job: God's infinite wisdom is the key to acknowledging his jus...
1. The Book of Job: God's infinite wisdom is the key to acknowledging his jus...1. The Book of Job: God's infinite wisdom is the key to acknowledging his jus...
1. The Book of Job: God's infinite wisdom is the key to acknowledging his jus...
COACH International Ministries
 
The Enchantment and Shadows_ Unveiling the Mysteries of Magic and Black Magic...
The Enchantment and Shadows_ Unveiling the Mysteries of Magic and Black Magic...The Enchantment and Shadows_ Unveiling the Mysteries of Magic and Black Magic...
The Enchantment and Shadows_ Unveiling the Mysteries of Magic and Black Magic...
Phoenix O
 
A375 Example Taste the taste of the Lord, the taste of the Lord The taste of...
A375 Example Taste the taste of the Lord,  the taste of the Lord The taste of...A375 Example Taste the taste of the Lord,  the taste of the Lord The taste of...
A375 Example Taste the taste of the Lord, the taste of the Lord The taste of...
franktsao4
 
Deerfoot Church of Christ Bulletin 6 9 24
Deerfoot Church of Christ Bulletin 6 9 24Deerfoot Church of Christ Bulletin 6 9 24
Deerfoot Church of Christ Bulletin 6 9 24
deerfootcoc
 
312 A Wise Woman of Abel Beth Maakah Saves The Town
312 A Wise Woman of Abel Beth Maakah Saves The Town312 A Wise Woman of Abel Beth Maakah Saves The Town
312 A Wise Woman of Abel Beth Maakah Saves The Town
Rick Peterson
 
Kala jadu (black magic) expert,Black magic specialist in Dubai vashikaran spe...
Kala jadu (black magic) expert,Black magic specialist in Dubai vashikaran spe...Kala jadu (black magic) expert,Black magic specialist in Dubai vashikaran spe...
Kala jadu (black magic) expert,Black magic specialist in Dubai vashikaran spe...
makhmalhalaaay
 
Hajj and umrah notes short procedure with important duas and translation
Hajj and umrah notes short procedure with important duas and translationHajj and umrah notes short procedure with important duas and translation
Hajj and umrah notes short procedure with important duas and translation
syedsaudnaqvi1
 
Vertical Church Kyiv Report 2022-2023: Church at war
Vertical Church Kyiv Report 2022-2023: Church at warVertical Church Kyiv Report 2022-2023: Church at war
Vertical Church Kyiv Report 2022-2023: Church at war
Olena Tyshchenko-Tyshkovets
 
How to Stop a Divorce and Save Your Marriage: Divorce Spells That Really Work...
How to Stop a Divorce and Save Your Marriage: Divorce Spells That Really Work...How to Stop a Divorce and Save Your Marriage: Divorce Spells That Really Work...
How to Stop a Divorce and Save Your Marriage: Divorce Spells That Really Work...
Traditional Healer, Love Spells Caster and Money Spells That Work Fast
 

Recently uploaded (16)

快速办理(PU毕业证书)普渡大学毕业证文凭证书一模一样
快速办理(PU毕业证书)普渡大学毕业证文凭证书一模一样快速办理(PU毕业证书)普渡大学毕业证文凭证书一模一样
快速办理(PU毕业证书)普渡大学毕业证文凭证书一模一样
 
A Free eBook ~ Valuable LIFE Lessons to Learn ( 5 Sets of Presentations)...
A Free eBook ~ Valuable LIFE Lessons    to Learn   ( 5 Sets of Presentations)...A Free eBook ~ Valuable LIFE Lessons    to Learn   ( 5 Sets of Presentations)...
A Free eBook ~ Valuable LIFE Lessons to Learn ( 5 Sets of Presentations)...
 
2. The Book of Psalms: Recognition of the kingship and sovereignty of God
2. The Book of Psalms: Recognition of the kingship and sovereignty of God2. The Book of Psalms: Recognition of the kingship and sovereignty of God
2. The Book of Psalms: Recognition of the kingship and sovereignty of God
 
yadadri temple history seva's list and timings
yadadri temple history seva's list and  timingsyadadri temple history seva's list and  timings
yadadri temple history seva's list and timings
 
The_Chronological_Life_of_Christ_Part_104_Repentance_and_Restoration
The_Chronological_Life_of_Christ_Part_104_Repentance_and_RestorationThe_Chronological_Life_of_Christ_Part_104_Repentance_and_Restoration
The_Chronological_Life_of_Christ_Part_104_Repentance_and_Restoration
 
Why is this So? ~ Do Seek to KNOW (English & Chinese).pptx
Why is this So? ~ Do Seek to KNOW (English & Chinese).pptxWhy is this So? ~ Do Seek to KNOW (English & Chinese).pptx
Why is this So? ~ Do Seek to KNOW (English & Chinese).pptx
 
The Hope of Salvation - Jude 1:24-25 - Message
The Hope of Salvation - Jude 1:24-25 - MessageThe Hope of Salvation - Jude 1:24-25 - Message
The Hope of Salvation - Jude 1:24-25 - Message
 
1. The Book of Job: God's infinite wisdom is the key to acknowledging his jus...
1. The Book of Job: God's infinite wisdom is the key to acknowledging his jus...1. The Book of Job: God's infinite wisdom is the key to acknowledging his jus...
1. The Book of Job: God's infinite wisdom is the key to acknowledging his jus...
 
The Enchantment and Shadows_ Unveiling the Mysteries of Magic and Black Magic...
The Enchantment and Shadows_ Unveiling the Mysteries of Magic and Black Magic...The Enchantment and Shadows_ Unveiling the Mysteries of Magic and Black Magic...
The Enchantment and Shadows_ Unveiling the Mysteries of Magic and Black Magic...
 
A375 Example Taste the taste of the Lord, the taste of the Lord The taste of...
A375 Example Taste the taste of the Lord,  the taste of the Lord The taste of...A375 Example Taste the taste of the Lord,  the taste of the Lord The taste of...
A375 Example Taste the taste of the Lord, the taste of the Lord The taste of...
 
Deerfoot Church of Christ Bulletin 6 9 24
Deerfoot Church of Christ Bulletin 6 9 24Deerfoot Church of Christ Bulletin 6 9 24
Deerfoot Church of Christ Bulletin 6 9 24
 
312 A Wise Woman of Abel Beth Maakah Saves The Town
312 A Wise Woman of Abel Beth Maakah Saves The Town312 A Wise Woman of Abel Beth Maakah Saves The Town
312 A Wise Woman of Abel Beth Maakah Saves The Town
 
Kala jadu (black magic) expert,Black magic specialist in Dubai vashikaran spe...
Kala jadu (black magic) expert,Black magic specialist in Dubai vashikaran spe...Kala jadu (black magic) expert,Black magic specialist in Dubai vashikaran spe...
Kala jadu (black magic) expert,Black magic specialist in Dubai vashikaran spe...
 
Hajj and umrah notes short procedure with important duas and translation
Hajj and umrah notes short procedure with important duas and translationHajj and umrah notes short procedure with important duas and translation
Hajj and umrah notes short procedure with important duas and translation
 
Vertical Church Kyiv Report 2022-2023: Church at war
Vertical Church Kyiv Report 2022-2023: Church at warVertical Church Kyiv Report 2022-2023: Church at war
Vertical Church Kyiv Report 2022-2023: Church at war
 
How to Stop a Divorce and Save Your Marriage: Divorce Spells That Really Work...
How to Stop a Divorce and Save Your Marriage: Divorce Spells That Really Work...How to Stop a Divorce and Save Your Marriage: Divorce Spells That Really Work...
How to Stop a Divorce and Save Your Marriage: Divorce Spells That Really Work...
 

The Compatibility Challenge:Examining R and Developing TERR

  • 1. The Compatibility Challenge: Examining R and Developing TERR Michael Sannella (msannell@tibco.com) TIBCO Spotfire http://spotfire.tibco.com These slides contain all the content from the useR!2014 poster with the same name
  • 2. What is TERR? • TERR: TIBCO® Enterprise Runtime for R • A commercial R-compatible statistics engine. • The latest in a family of scripting engines. • S, S-PLUS®, R, TERR • Embedded in Spotfire® • Provides R scripting, powers analytic tools. • Free Developer's Edition available. • Commercially available for custom integration. 2
  • 3. Why R Compatibility? • We developed TERR as a completely independent engine, without looking at R sources or documentation. • However, we want TERR to be able to load and run R packages from CRAN and other repositories, so TERR must be compatible with R. • Many CRAN packages work with TERR without change. • Some CRAN packages can be made to work with TERR if we rebuild them, without changing any of their code. • Some (hopefully few) CRAN packages require code changes to make them work under TERR. 3
  • 4. How to Achieve R Compatibility? • Our approach: Examine R’s behavior, write unit tests, and make TERR pass these tests. • R compatibility is a moving target: As R and the CRAN packages change over time, we must update TERR to follow. • R Wrinkles: While tracking down TERR incompatibility issues, we uncovered some interesting R behavior. • In some cases, we decided not to make TERR completely compatible with R. 4
  • 5. Developing Compatibility Using Key Packages • For some elements of R, a good way to develop compatibility was to focus on a key package or application that exercises certain functionality. • Key package: The CRAN Matrix package • Matrix fully exercised the S4 object system. • Getting the Matrix tests working gave us confidence that we had a compatible implementation of S4. • Key application: The RStudio GUI • RStudio exercised the R engine entries used to embed R within an application. • RStudio exercised source-code access via the “srcref” attribute on parsed expressions and functions. • RStudio exercised the trace, browser functions used for breakpoints and single-stepping. 5
  • 6. R Wrinkles: Character Encoding • TERR/R Incompatibility: R uses the "unknown" character encoding for most strings, whereas TERR uses the UTF-8 encoding by default. • R inconsistency: Character encoding of string constants. R-3.0.1/Linux > Encoding(c('abcxC4xyz', 'abcu00C4xyz')) [1] "unknown" "UTF-8" R-3.0.1/Windows (and TERR 2.6) > Encoding(c('abcxC4xyz', 'abcu00C4xyz')) [1] "latin1" "UTF-8" 6
  • 7. R Wrinkles: Character Encoding (2) • R inconsistency: The R/Windows parser doesn't accept many UTF-8 chars in names. R 3.1.0 Linux (and TERR 2.6): > typeof(parse(text="au30A4")[[1]]) [1] "symbol" R 3.1.0 Windows: > typeof(parse(text="au30A4")[[1]]) Error in parse(text = "a<U+30A4>") : <text>:1:7: unexpected symbol 1: a<U+30A4 ^ 7
  • 8. R Wrinkles: Non-Local Returns • Initially, we had problems using TERR in RStudio, which executes functions with the following form: function() { tryCatch(return(someCalc()), error=function(e) return("err"))} • The first argument to tryCatch is evaluated in a promise, but it can include a “non-local” return that unwinds the stack to the function where “return” appears. 8
  • 9. R Wrinkles: Non-Local Returns (2) • Consider the following code: yy <- function(expr, n) { cat("yy: n=", n, "n") if (n>1) { yy(expr, n-1) } else { expr } "yyret" } zz <- function(n) { yy(return(n), n) "zzret" } • When the expression expr is finally evaluated in yy, it unwinds multiple calls to yy, and returns from the outer function zz: > zz(3) yy: n= 3 yy: n= 2 yy: n= 1 [1] 3 > 9
  • 10. Compatibility Challenge: R’s C API • Many CRAN packages contain C code calling into the R engine via C entries (the “Rapi” API). • We implement Rapi entries in TERR as we find CRAN packages that need them. • Problem: the USE_RINTERNALS macro • If USE_RINTERNALS is defined, some R macros directly access R object structures, instead of calling Rapi entries. • This may improve performance for some code (but this is not a panacea). • This won't work with TERR, unless we make the TERR object structure identical to the R object structure. • Solution: Can gain compatibility for some packages by rebuilding the package without USE_RINTERNALS defined. 10
  • 11. Compatibility Challenge: Packages Including Base R Code • Symptom: Trying to run Matrix code, we saw an unexpected call to .Internal, though it didn’t appear in the Matrix sources: > checkMatrix(A) Error in .Internal: unimplemented .Internal function: drop • Reason: S4 setGeneric can incorporate base function definitions into a generic default method. • Matrix defines methods for drop, which creates a generic with base::drop as the default • Solution: When TERR loads a package with an S4 default method from a system library (base, stats, graphics, utils), it substitutes the TERR function from that library. 11
  • 12. Compatibility Challenge: The smoothEnds Problem • Symptom: In the IRanges package, the R system function stats::smoothEnds works with an IRanges Rle object: > x <- Rle((-4:4)^2) > options(dropRle = TRUE) > stats::smoothEnds(x) numeric-Rle of length 9 with 9 runs Lengths: 1 1 1 1 1 1 1 1 1 Values : 16 9 4 1 0 1 4 9 16 • However, this doesn't work in TERR: > x <- Rle((-4:4)^2) > options(dropRle = TRUE) > stats::smoothEnds(x) Error: 'y' must be numeric 12
  • 13. Compatibility Challenge: The smoothEnds Problem (2) • Reason: • TERR implements stats::smoothEnds in native C code. • Most likely, R implements it as R-language code, calling other arithmetic operators with methods defined for Rle objects. • Solution: • Rewrite TERR’s version of stats::smoothEnds as R- language code. • Deeper issue: • A TERR algorithm has to call the same methods as R, if they can be redefined for particular object classes. 13
  • 14. For More Information • Drop by the TIBCO booth. • Attend our talks: • Louis Bajuk-Yorgan: “Deploying R into Business Intelligence and Real-time Applications” • (Business track, Session 5, Wednesday 16:00) • Stephen Kaluzny: “Software Testing and the R Language” • (Business track, Session 6, Thursday 10:00) • Spotfire and TERR: • http://spotfire.tibco.com/terr • TERR Developer’s Edition: • http://www.tibcommunity.com/community/products/analytics/terr • http://tap.tibco.com/ • https://docs.tibco.com/products/tibco-enterprise-runtime-for-r 14