R - R Markdown (Rmd)

> Procedural Languages > R

1 - About

The R Markdown format of RStudio.

2 - Setup

A tex windows distribution must be installed to output PDF

Advertising

3 - Syntax

3.1 - Markdown

See:

---
title: "OBIEE Timesten Analysis"
author: "Nicolas GERARD"
output:
  html_document:
    toc: yes
    toc_depth: 2
    number_sections: true
    code_folding: hide
---

Running command:

"C:/RStudio/bin/pandoc/pandoc" 
           +RTS 
           -K512m 
           --RTS load_analysis_timesten_response_time_2.utf8.md 
           --to html 
           --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash 
           --output load_analysis_timesten_response_time_2.html 
           --smart 
           --email-obfuscation none 
           --self-contained 
           --standalone 
           --section-divs 
           --table-of-contents 
           --toc-depth 3 
           --template "C:\R\R-3.3.2\library\rmarkdown\rmd\h\default.html" 
           --no-highlight 
           --variable highlightjs=1 
           --variable "theme:bootstrap" 
           --include-in-header "C:\Users\gerard\AppData\Local\Temp\RtmpyeMj5c\rmarkdown-str113b0498e512d.html" 
           --mathjax 
           --variable "mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"'

3.3 - Data Frame (Table)

3.4 - Chunk Options

3.4.1 - Knitr Chunk options

Knitr Chunk options

  • Example: Insert a chunk that will not be evaluated (only for highlighting)
```{sql eval=FALSE, echo=TRUE}
SET VARIABLE QUERY_SRC_CD='Report';SELECT
   0 s_0,
   "Billing Cube"."Currency"."Currency Code" s_1
FROM "Billing Cube"
ORDER BY 1, 2 ASC NULLS LAST
FETCH FIRST 2000001 ROWS ONLY
```
Advertising

3.4.2 - Figure sizes

Figure sizes are specified in inches and can be included as a global option of the document output format. For example:

---
title: "My Document"
output:
  html_document:
    fig_width: 6
    fig_height: 4
---

You can also specify figure sizes on a per-chunk basis. For example, to create a dygraph that is smaller than the default (7×5) you could do this:

```{r, fig.width=6, fig.height=2.5}
....
```

3.5 - Parameters

4 - Example

4.1 - Running SQL

  • Get a connection object
drv <- JDBC("oracle.jdbc.OracleDriver", classPath=CLASSPATH, " ")
con <- dbConnect(drv, DB_URL_FULL)
  • Run it and retrieve it as variable
```{sql, connection = con, echo =TRUE, output.var="total"}
select sum(quantity) from sales
```
Advertising

5 - HTML Widget

ggplotly(
       ggplot(res_dbrowcount,
       aes(
           x=cubes, 
           y=res_dbrowcount$CUM_NUM_DB_ROW, 
           color=cubes,  
           label=res_dbrowcount$CUM_NUM_DB_ROW) # Tooltip
           ) +
       geom_jitter(width= 0.1 , alpha = 0.5) +
       labs(
          x="Subject Area",
          y="Row Count", 
          color="Cubes", 
          title="Database Row Count by Subject Area (Bigger than 10)"
          ) +
       guides(color=FALSE) +
       theme(legend.position="none")
)

6 - Documentation / Reference

lang/r/rmd.txt · Last modified: 2018/11/23 15:43 by gerardnico