First we set a flag -p
for the coffee
engine to print the JavaScript output instead of evaluating the code (engine.opts = '-p'
):
knitr::opts_chunk$set(cache = TRUE, engine.opts = '-p')
You need to install coffee
, the command-line version of CoffeeScript.
CoffeeScript compiles javascript:
@square = (x) -> x * x
To use CoffeeScript in an HTML document, use results="asis"
, echo=FALSE
, and wrap the chunk in <script>
tags.
Of course you can also run the code, if you remove the -p
flag from the chunk option engine.opts
(I'm not evaluating this code chunk here because I do not have a proper version of coffee
on Debian yet; if you do, you can remove eval=FALSE
):
x = 42 console.log "The answer is ", x
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.