Skip to content

Instantly share code, notes, and snippets.

@ashander
Last active August 29, 2015 14:07
Show Gist options
  • Save ashander/a66a7df67668c534ef64 to your computer and use it in GitHub Desktop.
Save ashander/a66a7df67668c534ef64 to your computer and use it in GitHub Desktop.
minimal example for knitr externalization issue
## @knitr my-external-chunk
set.seed(111)
rnorm(100)
## ----begin---------------------------------------------------------------
read_chunk('extern-test.R')
#
library(knitr)
## ----my-external-chunk---------------------------------------------------
set.seed(111)
rnorm(100)
\documentclass{article}
\begin{document}
\title{A Minimal Demo of knitr}
\author{Jaime Ashander}
\maketitle
<<begin>>=
read_chunk('extern-test.R')
#
library(knitr)
@
<<my-external-chunk>>=
@
\end{document}

Code externalization example

library(knitr)
read_chunk('extern-test.R') 
set.seed(111)
rnorm(100)
##   [1]  0.23522071 -0.33073587 -0.31162382 -2.30234566 -0.17087604
##   [6]  0.14027823 -1.49742666 -1.01018842 -0.94847560 -0.49396222
##  [11] -0.17367413 -0.40659878  1.84563626  0.39405411  0.79752850
##  [16] -1.56666536 -0.08585101 -0.35913948 -1.19360897  0.36418674
##  [21]  0.36166245  0.34696437  0.18973653 -0.15957681  0.32654924
##  [26]  0.59825420 -1.84153430  2.71805560  0.19124439 -1.30129607
##  [31] -3.11321730 -0.94135740  1.40025878 -1.62047003 -2.26599596
##  [36]  1.16299359 -0.11615504  0.33425601 -0.62085811 -1.30984491
##  [41] -1.17572604 -1.12121553 -1.36190448  0.48112458  0.74197163
##  [46]  0.02782463  0.33137971  0.64411413  2.48566156  1.95998171
##  [51]  0.19166338  1.55254427  0.91424229  0.35862537  0.17509564
##  [56] -0.84726777  0.97823166  1.80586826  0.12291480 -0.12977203
##  [61] -0.21642866  1.44647817  0.40970980  0.91091657  1.43035817
##  [66] -0.38129196  0.20230718 -0.80619919  0.29463418  1.40488308
##  [71]  1.02376685  0.47612606 -0.67033033  0.15923432 -0.38271538
##  [76]  0.93576259 -0.63153227 -0.09830608  1.03198498  0.38780843
##  [81] -1.25612931 -0.78695273  0.42981155 -0.37641622 -1.21622907
##  [86]  1.02927851  0.43039700 -1.24557402 -0.60272849  0.66006939
##  [91]  2.05074953  0.49080818 -1.73147942  0.71088366  0.01382291
##  [96] -1.40104160  1.25912367 -0.12747752 -0.72938651 -1.21136136
## ----begin---------------------------------------------------------------
read_chunk('extern-test.R')
#
library(knitr)
## ----my-external-chunk---------------------------------------------------
set.seed(111)
rnorm(100)
Code externalization example
========================================================
```{r begin}
read_chunk('extern-test.R')
#
library(knitr)
```
```{r my-external-chunk}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment