Opal Reporting with R

This is an example of how to use knitr for producing reports on data stored in Opal.

Procedure

The requirement on client side is to have opal package installed:

install.packages("opal", repos = c(getOption("repos"), "http://cran.obiba.org"), 
    dependencies = TRUE)

The requirements on server side is:

alt text

The procedure is then the following:

Example

Load the required libraries on client side and login in Opal (credentials and output are hidden)…

Assign some variables into a data.frame with associated D symbol in R on Opal server side:

opal.assign(o, "D", "mica_demo.FNAC", variables = c("SVUOSI", "SUKUP", "PITUUS", 
    "PAINO"))

Preview the assigned data.frame:

opal.execute(o, "head(D)")
##                     SVUOSI SUKUP PITUUS PAINO
## 1000502517535681229   1956     2  1.718 50.60
## 1007286407843912597   1972     1  1.625 68.67
## 1007294810171882184   1975     2  1.691 77.93
## 1008306342245432754   1958     1  1.666 78.29
## 1008983561370747969   1960     1  1.661 87.72
## 1011258566350785406   1969     2  1.744 55.51

Summary of the assigned data.frame:

opal.execute(o, "summary(D)")
##      SVUOSI     SUKUP        PITUUS          PAINO       
##  Min.   :1933   1:1512   Min.   :1.372   Min.   : 40.10  
##  1st Qu.:1944   2:1488   1st Qu.:1.624   1st Qu.: 67.08  
##  Median :1957            Median :1.683   Median : 77.40  
##  Mean   :1957            Mean   :1.684   Mean   : 77.87  
##  3rd Qu.:1970            3rd Qu.:1.747   3rd Qu.: 88.74  
##  Max.   :1982            Max.   :2.009   Max.   :137.41

Histogram figure of the PITUUS variable:

plot(opal.execute(o, "hist(D$PITUUS)"))

plot of chunk unnamed-chunk-6

Loading ggplot2 library in R on Opal server side… This will fail if ggplot2 is not installed in R server environment.

Plot PITUUS vs. PAINO with “lm” smoothing:

opal.execute(o, "qplot(PITUUS,PAINO, data=D) + geom_smooth(method=\"lm\")")

plot of chunk unnamed-chunk-8

Cleaning the resources on Opal server side…