Slide 1

Slide 1 text

Kara Woo posit::conf(2023) R not only in production

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

How can the strengths of R, and the people who use it, influence the organization as a whole?

Slide 6

Slide 6 text

Meet Angela

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Vancomycin can treat MRSA

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

There’s no one dose that works for everyone

Slide 11

Slide 11 text

We use pharmacological models + patient’s unique characteristics to recommend the optimal dose

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Patient data, lab results, past doses

Slide 14

Slide 14 text

Patient data, lab results, past doses Recommended dose

Slide 15

Slide 15 text

R is core to our product

Slide 16

Slide 16 text

R is core to fulfilling our mission

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

ETL

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

• REST API • Data processing pipeline • Analyses and new models • Model validation • Regulatory reporting • New product prototypes • …

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

{ "firstName": "First name", "lastName": "Last name", "dob": "Date of birth", "changeMyPassword": "Change my password", "logout": "Logout", ... } { "firstName": "Vorname", "lastName": "Nachname", "dob": "Geburtsdatum", "changeMyPassword": "Ändere mein Passwort", "logout": "Ausloggen", ... }

Slide 28

Slide 28 text

{ "firstName": "First name", "lastName": "Last name", "dob": "Date of birth", "changeMyPassword": "Change my password", "logout": "Logout", ... }

Slide 29

Slide 29 text

{ "firstName": "First name", "lastName": "Last name", "dob": "Date of birth", "age": "Age", "changeMyPassword": "Change my password", "logout": "Logout", ... } 👀

Slide 30

Slide 30 text

{ "firstName": "First name", "lastName": "Last name", "dob": "Date of birth", "age": "Age", "changeMyPassword": "Change my password", "logout": "Logout", ... } { "firstName": "Vorname", "lastName": "Nachname", "dob": "Geburtsdatum", "changeMyPassword": "Ändere mein Passwort", "logout": "Ausloggen", ... } 👀

Slide 31

Slide 31 text

{ "firstName": "First name", "lastName": "Last name", "dob": "Date of birth", "age": "Age", "changeMyPassword": "Change my password", "logout": "Logout", ... } { "firstName": "Vorname", "lastName": "Nachname", "dob": "Geburtsdatum", "age": "Alter", "changeMyPassword": "Ändere mein Passwort", "logout": "Ausloggen", ... } 👀

Slide 32

Slide 32 text

The mindset of R as a first class language empowers us to solve problems.

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

We can do this in R!

Slide 37

Slide 37 text

💡 Idea

Slide 38

Slide 38 text

💡 Idea “It works on my machine”

Slide 39

Slide 39 text

💡 Idea “It works on my machine” ? Final product ? ?

Slide 40

Slide 40 text

💡 Idea “It works on my machine” ? Final product ? ?

Slide 41

Slide 41 text

Reliability Deployability

Slide 42

Slide 42 text

We need to detect kidney injury accurately, all the time.

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Elevated creatinine suggests kidney damage Easy, right? • Data gaps • Out of order data • Data in di ff erent units • Missing baseline • Non-numeric data • Data entry errors

Slide 45

Slide 45 text

test_that("AKI stage is calculated correctly", { result <- calc_aki_stage( scr = c(0.7, 1.0), t = c(0, 24), egfr = c(60, 40) ) expect_equal(result$stage, "stage 1") })

Slide 46

Slide 46 text

test_that("AKI stage is calculated correctly", { result <- calc_aki_stage( scr = c(0.7, 1.0), t = c(0, 24), egfr = c(60, 40) ) expect_equal(result$stage, "stage 1") })

Slide 47

Slide 47 text

test_that("AKI stage is calculated correctly", { result <- calc_aki_stage( scr = c(0.7, 1.0), t = c(0, 24), egfr = c(60, 40) ) expect_equal(result$stage, "stage 1") })

Slide 48

Slide 48 text

test_that("AKI stage is calculated correctly", { result <- calc_aki_stage( scr = c(0.7, 1.0), t = c(0, 24), egfr = c(60, 40) ) expect_equal(result$stage, "stage 1") })

Slide 49

Slide 49 text

test_that("stage correct: 0.3 mg/dl rise", { # ... }) test_that("stage correct: 1.5x baseline rise", { # ... }) test_that("sorts times correctly", { # ... }) test_that("handles non-numeric inputs", { # ... }) test_that("handles only 1 observation", { # ... })

Slide 50

Slide 50 text

Jenny Bryan “If you use software that lacks automated tests, you are the tests.”

Slide 51

Slide 51 text

Get latest code Build the R package Run the tests Continuous integration

Slide 52

Slide 52 text

5d01863 Add function to detect AKI ✅ a28vf11 Rewrite AKI function to improve performance ❌ 682hcKa Fix handling of missing data ✅

Slide 53

Slide 53 text

Continuous integration • Find bugs quickly • Be lazy free up time for more important work • Make sure the code continues to behave as intended

Slide 54

Slide 54 text

💡 Idea “It works on my machine” ? Final product Testing Continuous Integration

Slide 55

Slide 55 text

💡 Idea “It works on my machine” Docker Final product Testing Continuous Integration

Slide 56

Slide 56 text

R R packages your code Docker

Slide 57

Slide 57 text

FROM rstudio/plumber:v1.1.0 RUN Rscript -e "install.packages('clinPK')" COPY . /myproject WORKDIR /myproject ENTRYPOINT ["Rscript", "entrypoint.R"] Dockerfile

Slide 58

Slide 58 text

FROM rstudio/plumber:v1.1.0 RUN Rscript -e "install.packages('clinPK')" COPY . /myproject WORKDIR /myproject ENTRYPOINT ["Rscript", "entrypoint.R"] Dockerfile

Slide 59

Slide 59 text

FROM rstudio/plumber:v1.1.0 RUN Rscript -e "install.packages('clinPK')" COPY . /myproject WORKDIR /myproject ENTRYPOINT ["Rscript", "entrypoint.R"] Dockerfile

Slide 60

Slide 60 text

FROM rstudio/plumber:v1.1.0 RUN Rscript -e "install.packages('clinPK')" COPY . /myproject WORKDIR /myproject ENTRYPOINT ["Rscript", "entrypoint.R"] Dockerfile

Slide 61

Slide 61 text

FROM rstudio/plumber:v1.1.0 RUN Rscript -e "install.packages('clinPK')" COPY . /myproject WORKDIR /myproject ENTRYPOINT ["Rscript", "entrypoint.R"] Dockerfile

Slide 62

Slide 62 text

FROM rstudio/plumber:v1.1.0 RUN Rscript -e "install.packages('clinPK')" COPY . /myproject WORKDIR /myproject ENTRYPOINT ["Rscript", "entrypoint.R"] Dockerfile https://github.com/karawoo/dockerdemo

Slide 63

Slide 63 text

Image: Royyan Razka, Noun Project

Slide 64

Slide 64 text

Get latest code Build the 
 R package Run the tests Continuous integration

Slide 65

Slide 65 text

Get latest code Build the docker image Run the tests Continuous integration

Slide 66

Slide 66 text

💡 Idea “It works on my machine” Docker Final product Testing Continuous Integration

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

We are motivated to answer questions

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

Database query was too slow

Slide 72

Slide 72 text

Database query was too slow Added an index to the database

Slide 73

Slide 73 text

Database query was too slow Added an index to the database Data processing pipeline was too slow

Slide 74

Slide 74 text

Database query was too slow Added an index to the database Data processing pipeline was too slow Removed the index

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

If you can’t make changes because you’re afraid of breaking something, it’s already broken.

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

We can visualize and communicate our findings

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

Tests test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... })

Slide 81

Slide 81 text

Tests test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) test_that("...", { # ... }) become data

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

We are used to dealing with uncertainty

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

Motivated to answer questions Skilled at visualizing and communicating results Able to handle uncertainty

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

Using R throughout the stack = doing science throughout the stack

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

pos.it/slido-keynote