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.

library(knitr)
```r
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():

read_chunk(lines = demo.sub, labels = 'rgl-sub')

That means we assigned the code to a chunk named rgl-sub, which appears below:


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:

library(rgl)
knit_hooks$set(rgl = hook_rgl)

Now you can see the 3D plot:




Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on May 20, 2021, 5:08 p.m.