-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExamples_R_Markdown.Rmd
162 lines (109 loc) · 3.39 KB
/
Examples_R_Markdown.Rmd
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
title: "R Notebook"
output: html_notebook
# uncomment following line to run the example with custom widgets
# runtime: shiny
---
### Basic markdown
You can *underline*, **bold**, ~~strike-through~~, add `code`, and format text in many other ways, see: [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) (both Jupyter and R Markdown)
For R Markdown specific features that depart from standard Markdown see [R Markdown Cheatsheet](https://rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf).
### Equations
You can use LaTeX:
$${\displaystyle \mathbf {X} =\mathbf {U} \mathbf {\Sigma } \mathbf {W} ^{T}}$$
where $\mathbf {\Sigma }$ is a diagonal matrix with singular values of $\mathbf {X}$
### Plots
```{r}
library(ggplot2)
df = data.frame(x=c(1, 2, 2, 3))
ggplot(df, aes(x=x)) + geom_density(fill='#59A14F')
```
### Fasta
```{r}
# install.packages("msaR")
library(msaR)
seqfile <- system.file("sequences", "AHBA.aln", package="msaR")
msaR(seqfile)
```
### Molecular structures
Using [r3dmol](https://github.com/swsoyee/r3dmol). In development.
```{r}
# install.packages("r3dmol")
library(r3dmol)
r3dmol() %>%
m_add_model(data = pdb_6zsl, format = "pdb") %>%
m_zoom_to() %>%
m_set_style(style = list(cartoon = list(color = 'spectrum')))
```
### Imaging data
Embedding 3D images in notebooks is possible, but does not always work.
```{r, echo=FALSE}
# sudo apt install libglu1-mesa-dev freeglut3-dev mesa-common-dev
# install.packages("nat")
# library(nat)
# brain = read.nrrd('data/005_32months_T2_RegT1_Reg2Atlas_ManualBrainMask_Stripped.nrr')
# open3d()
# plot3d(brain)
```
### Networks and pathways
There are multiple ways to communicate with cytoscape from R. Either static images can be embedded, or interactive plots can be served with shiny.
- cyjShinyOutput
- KEGGscape
- RC3
### Custom widget
Custom widgets can be created using shiny:
```{r echo=FALSE}
library(shiny)
sliderInput("m", h3("m"), min=-2, max=2, value=0, step=0.01)
sliderInput("b", h3("b"), min=-3, max=3, value=0, step=0.5)
renderPlot({
m = input$m
b = input$b
x = seq(-100, 100) / 10
df = data.frame(x=x, y=m * x + b)
(
ggplot(df, aes(x=x, y=y))
+ geom_point()
+ coord_fixed()
+ ylim(-10, 10)
)
})
```
### Explaining code details
Whether you want to get help, or explain how a specific fragment of code works without repeating yourself, you can do that with built-in question mark operator.
In this example let's see what are the arguments of `sd` function, and how it is implemented.
To get help on a function usage prepend `?`(note: append is not supported in R markdown notebooks)
```{r}
?sd
```
To search for other implementations use `??`
```{r}
??sd
```
Differently to Jupyter, the content is displayed but not stored.
### Multi-lingual - bash example
Change the language identifier to use bash:
```{bash}
pwd
```
Create a file with one word *test*:
```{bash}
echo "test" > test.txt
```
md5sum is a simple command which you can run on Linux (md5 on Mac) to get a *short* reproducible string which will *very likely* change significantly if the file contents changes.
```{bash}
md5sum test.txt
```
If we change it slightly:
```{bash}
echo "test2" > test.txt
md5sum test.txt
```
If we revert back:
```{bash}
echo "test" > test.txt
md5sum test.txt
```
### Multi-lingual - Python inside R
```{python, python.reticulate = FALSE}
print("Hello word!")
```