kntir demonstration
You can generate blog posts using the knitr R package. Don’t be fooled, even though it is an R package, it allows one to run commands in Python and bash. Before you get going in knitr, be sure to see the Resources page for tutorials on how to use knitr.
To get going, a template file should be copied from
_post_templates/YYYY-MM-DD-knitr-post-name.Rmd
, put into the _knitr
folder,
and renamed appropriately. Be sure to change the YAML front matter including the
date and the title of the post. The first time you ever create a knitr document
may need to run the following commands from the terminal:
chmod +x render_post.R
chmod +x render_post.sh
pip install watchdog
Now you have three options for your workflow. The first is to bang out your knitr document and then run:
./render_post.R 2014-11-04-using_knitr.Rmd
This will run the Rmd file and copy the markdown file into the _posts
folder.
Alternatively, you could run:
./render_post.sh 2014-11-04-using_knitr.Rmd
If you already have the local version of the website loaded or you go ahead and load it now, then whenever you hit refresh on your browser the page will be updated.
The third option is to
Below is a minimal R markdown example that I’ve swiped from the knitr GitHub site plus some other goodies I’ve added to demonstrate that you can use bash and Python commands within knitr documents.
A minimal R Markdown example
A quote:
Markdown is not LaTeX.
code chunks
A paragraph here. A code chunk below (remember the three backticks):
1+1
## [1] 2
.4-.7+.3 # what? it is not zero!
## [1] 5.551115e-17
graphics
It is easy.
plot(1:10)
hist(rnorm(1000))
inline code
Yes I know the value of pi is 3.1415927, and 2 times pi is 6.2831853.
nested code chunks
You can write code within other elements, e.g. a list
- foo is good
strsplit('hello indented world', ' ')[[1]]
## [1] "hello" "indented" "world"
- bar is better
bash code chunks
ls *.Rmd
## 2014-11-04-using-knitr.Rmd
python code chunks
print "Hello, World!"
## Hello, World!
perl code chunks
print "Hello, World!\n"
## Hello, World!
conclusion
Nothing fancy. You are ready to go. When you become picky, go to the knitr website.