-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtutorial_knitr_version3.rmd
More file actions
147 lines (92 loc) · 2.8 KB
/
tutorial_knitr_version3.rmd
File metadata and controls
147 lines (92 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
output:
knitrBootstrap::bootstrap_document:
title: "Rmarkdown_for_Journal_club"
theme: amelia
highlight: sunburst
theme.chooser: TRUE
highlight.chooser: TRUE
---
library(knitr)
library(markdown)
knit('tutorial_knitr_version3.rmd')
markdownToHTML("tutorial_knitr_version3.md", "tutorial_knitr_version3.html",fragment.only = TRUE)
This is an R Markdown document, which present the basis element to work with the knitr package in the goal to create some reports.
Here, we presente a collection of tricks to work with knitr in R studio server.
# Why use knitR?
- Generate Report in HMTL, PDF, DOC
- more easier that latex
- integrate in R studio
- combine all elements : documentation, code, result...
- includes Figure, table, summaries :
- allows many operation such as loops
- use Rmarkdown language
# Rmarkdown
- like HTML but without HTML tag
- include R code.
# Rmarkdown commands.

# Create a new Rmarkdown document.

# include a R code in Rmarkdown document
- the R code is executed in a chunk
- the variable are global
- the Rmarkdown could have many options (or not).
## Chunk options
Many options are available to control the R code execution

## Three ways to include a table
### With ktable
```{r results='asis'}
# create a data.frame structure.
library(knitr)
mydata = data.frame(value1= 1:4, value2= 6:9)
rownames(mydata) <- paste("gene", 1:4)
kable(mydata, include.rownames=TRUE)
```
### With googlevis
```{r results='asis'}
library(googleVis)
mydata = data.frame(value1= 1:100, value2= 6:105)
rownames(mydata) <- paste("gene", 1:100)
table = gvisTable(mydata,options=list(page='enable', height='automatic', width='automatic'))
table
```
### With DT package
```{r results='asis'}
library(DT)
table = datatable(mydata, class = 'cell-border stripe')
table
```
## include a plot.
2 strategies to do that:
### from a R code directly:
Here, we precise no option for the R chunk
```{r}
mydata =rnorm(1000)
plot(mydata, cex= 0.4)
```
In this case, we precise several options in the features of the plot
```{r, fig.height= 14, fig.width= 14, fig.align='center'}
mydata =rnorm(1000)
plot(mydata, cex= 0.4, col= "red")
```
### from a file:
R code to generate the plot
```{r}
png("figure/plot2insert.png")
plot(mydata, cex= 0.4, col= "blue")
dev.off()
```
Include the plot with the markdown syntax.

# Strategie with big Data or big Computation:
1. In the case, where you have a large dataset to analyze, it's important to review the
## Conclusion :
- Easy to use
- One document for Script, documentation, result, reproducible.
- allows the interactive documentation
## To go further:
- CSS style
- Rpres
- include loops and template.