Permalink
Browse files

opts_knit$set(base.url) might be confusing to beginners, so remove it…

… in Rmd and put it in Rscript -e instead
  • Loading branch information...
1 parent 32ce593 commit e85848c6c2e3464fdc5d6c74154d19b049f32926 @yihui committed May 24, 2012
Showing with 12 additions and 10 deletions.
  1. +6 −1 inst/examples/knit-all.R
  2. +6 −9 inst/examples/knitr-minimal.Rmd
@@ -17,7 +17,12 @@ for (i in list.files(pattern = '\\.lyx$')) {
for (i in list.files(pattern = '\\.R(tex|md|html|rst)')) {
message(i)
- stopifnot(identical(system(sprintf('knit %s', i)), 0L))
+ cmd = if (i == 'knitr-minimal.Rmd') {
+ sprintf("Rscript -e 'library(knitr);opts_knit$set(base.url=\"https://github.com/yihui/knitr/raw/master/inst/examples/\");opts_chunk$set(fig.path=\"\");knit(\"%s\")'", i)
+ } else {
+ sprintf('knit %s', i)
@krlmlr
krlmlr Nov 2, 2013

What is the knit system command? Compiling examples fails for me at this point.

@yihui
yihui Nov 2, 2013 owner

it is under inst/bin/; I have a symbolic link of it to ~/bin/, which is in my PATH

+ }
+ stopifnot(identical(system(cmd), 0L))
flush.console()
}
@@ -1,4 +1,3 @@
-`r opts_chunk$set(fig.width=5, fig.height=5, fig.path='')`
This is a minimal example of using **knitr** with in HTML pages. I am actually
using markdown here since it is more convenient in GitHub.
@@ -7,12 +6,10 @@ First, the input file was named as `knitr-minimal.Rmd`
and **knitr** will automatically determine the output filename to be
`knitr-minimal.md` (`*.Rmd --> *.md`).
-I used the code below to make sure **knitr** writes correct URL's for my images.
-
-``` {r setup}
-# you do not need this unless you also commit images to your Github repository
-opts_knit$set(base.url='https://github.com/yihui/knitr/raw/master/inst/examples/')
-````
+```{r setup}
+# set global chunk options: images will be 5x5 inches
+opts_chunk$set(fig.width=5, fig.height=5)
+```
Now we write some code chunks in this markdown file:
@@ -22,14 +19,14 @@ Now we write some code chunks in this markdown file:
## boring random numbers
set.seed(123)
rnorm(5)
-````
+```
We can also produce plots:
``` {r md-cars-scatter, message=FALSE}
library(ggplot2)
qplot(hp, mpg, data=mtcars)+geom_smooth()
-````
+```
Inline R code is also supported, e.g. the value of `x` is `r x`, and 2 times pi
= `r 2*pi`.

0 comments on commit e85848c

Please sign in to comment.