Calling r from net a case study using rapid nca the non compartmental analysis workflow tool
Sponsored Links
This presentation is the property of its rightful owner.
1 / 33

Calling R from .NET: a case-study using Rapid NCA, the non-compartmental analysis workflow tool PowerPoint PPT Presentation

  • Uploaded on
  • Presentation posted in: General

Calling R from .NET: a case-study using Rapid NCA, the non-compartmental analysis workflow tool. Chris Campbell. Agenda. Using .NET Identify Opportunity Design Solution Develop Solution Connections with R.NET Complete & Deploy T ool. Using .NET What is .NET?.

Download Presentation

Calling R from .NET: a case-study using Rapid NCA, the non-compartmental analysis workflow tool

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Calling R from .NET: a case-study using Rapid NCA, the non-compartmental analysis workflow tool

Chris Campbell


  • Using .NET

  • Identify Opportunity

  • Design Solution

  • Develop Solution

  • Connections with R.NET

  • Complete & Deploy Tool

Using .NETWhat is .NET?

  • Object-oriented environment to develop applications

  • Safe execution environment

  • Choice of programming languages

  • Framework consisting of:

    • runtime

    • class library

  • Developed with Visual Studio

Using .NETVisual Studio

  • A graphical programming tool (IDE)

  • Also, Visual Studio Express is a free version

Using .NETChoice of languages

  • Tried and tested languages

  • C# is the main one

  • F# is a functional language (not a steep learning curve if you know OCaml)

  • Knowledge of XAML (a Microsoft declarative XML language) is required for state of the art graphics

  • C++/CLI useful for legacy and bespoke parallel processing (including GPGPU)

  • Other possibilities..

  • Vb.Net is very like C# (no advantage over it)

  • Third parties have added languages to the CLI platform

Using .NETAn “ajar source” platform

  • Not exactly open source, but…

  • Most CLI third party languages are open

  • C# and VB.Net are not – but many open source projects based on them

  • Microsoft have made F# open source

  • There are free (Express) versions of Visual Studio for the languages

  • Compiler is free and other editors / IDEs are available (but not usually preferred by developers)

Using .NETPerformance and Computation

  • Performance is very good

  • On graphics (millions of data points will plot with ease and zoom smoothly)

  • Computation is fast enough in C#, calling R adds little overhead

  • Standard Maths library is limited; third parties and MS maths for “drawing” are better

  • Data parallel computation is possible on the desktop (GPGPU)

  • F# provides further “big data” capabilities

A Project Case Study

Identify Opportunity

  • Where can repetitive tasks be automated?

  • How can regular outputs be generated?

  • How can we make methods and techniques more accessible to colleagues?

Identify Opportunity

  • Customer needed to send monthly reports to dozens of trial centres

  • Small team, so time limited

  • Normally simple non-compartmental analysis, standard report

Design Solution

  • What is the simplest way for the task to be performed?

  • Which steps can be eliminated?

  • What are barriers to understanding for users?

Design SolutionStreamline WorkflowWhat is Needed?

  • Import data to analysis software

  • Map variables

  • Select units

  • Select non-compartmental

  • Select model

  • Select interpolation

  • Select rules for BLQ

  • Select terminal phase calculation method

  • Perform analysis

  • Choose partial area

  • Export results

  • Export plots

  • Write report

  • Format report

Design SolutionAnalysis Engine using R

Let’s get .Net technical..

Connections with R.NET

  • What will be provided to R?

  • What will be returned from R?

  • What happens if something goes wrong?

Connections with R.NETUsing the R Service

  • R.NET allows R calls to be submitted to an R service

  • R.NET is not the only option

  • R.NET connects to R down to Expression level

  • So objects can effectively be passed back into .NET

  • Recommend a robust .Net framework to do this

_pluginsManager = newRPluginManager(PluginLocation, RLocation);


_session = _pluginsManager.GetSession();

boolsessionOk = _pluginsManager.TryMakeSession(out_session);

Connections with R.NET

  • R is efficiently accessed, via R.Net (as pictured in Visual Studio) via a Plugin (as above)

Connections with R.NET“Engineer’s” framework

Connections with R.NETRobustness

  • Function may be passed data outside it’s anticipated structure

> checkOrderedVector(c(0, 1, 3, 2, 4),

+ description = "Time")

Error in checkOrderedVector(c(0, 1, 3, 2, 4),

description = "Time") :

Error: Time is not ordered. Actual value is 0 1 3 2 4


Connections with R.NETRobustness

  • The tool expects a certain return object

  • An error in an R call should be trapped by the communicating function

  • Return object passed as normal

  • An error checking element of the return object can report information about the error

> check01 <- try(checkOrderedVector(Time,

+ description = "Time"), silent = TRUE)


_pluginsManager = newRPluginManager(PluginLocation, RLocation);


_session = _pluginsManager.GetSession();

boolsessionOk = _pluginsManager.TryMakeSession(out_session);

_session.SetNumericSymbol("TimePtVector", CheckTimePointData(toAnalyse));

_session.SetNumericSymbol("ConcVector", CheckConcentrationPointData(toAnalyse));

varevalString = string.Format("ncaAnalysis(TimePtVector, ConcVector, …

MathEngineDataRowDto<double> ncaGetBack =

_session.PerformNumericEvaluation(evalString, "ROutput_Error");

_lastErrors = ncaGetBack.ErrorStrings;



Connections with R.NETUsing the framework

A Rapid Solution

Complete & Deploy Tool

  • Can users understand how to use tool?

  • How confident are we in tool output?

Deploy Tool

Data Import

Map Variables

Review Analysis

Review Grouping

Generate Report

Select Report Type

Add Group Comments

View Report


  • Great graphical interfaces can be built using .NET

  • Intuitive interactive features are available

  • R.NET allows R analysis to be accessed as a service

  • Good coding practice will ensure application is robust

  • Work on a well engineered framework will be rewarded with desktop solutions created at high speed

  • Login