-
Notifications
You must be signed in to change notification settings - Fork 586
/
046-read-rforge.Rmd
32 lines (23 loc) · 970 Bytes
/
046-read-rforge.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
This demo shows you how to reference code in a URL. We use R-Forge as an example, but you can really read code from anywhere.
We cache this chunk so that the next time we compile this document, the code does not need to be read from the web again.
```{r setup}
library(knitr)
```{r read-code, cache=TRUE}
demo.sub = read_rforge('rgl/demo/subdivision.r', project = 'rgl')
head(demo.sub)
```
Once we have the source code, we can insert it into **knitr** with `read_chunk()`:
```{r}
read_chunk(lines = demo.sub, labels = 'rgl-sub')
```
That means we assigned the code to a chunk named `rgl-sub`, which appears below:
```{r rgl-sub, eval=FALSE}
```
You can actually run the code and capture the rgl plot, but before that we need to load the package and set a rgl hook:
```{r}
library(rgl)
knit_hooks$set(rgl = hook_rgl)
```
Now you can see the 3D plot:
```{r rgl-sub, rgl=TRUE, fig.height=4, fig.width=4, echo=-(1:4), results='hide', cache=TRUE, warning=FALSE}
```