packages feed

Rlang-QQ-0.2.0.0: examples/test6.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title></title>
  <style type="text/css">
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; }
code > span.dt { color: #902000; }
code > span.dv { color: #40a070; }
code > span.bn { color: #40a070; }
code > span.fl { color: #40a070; }
code > span.ch { color: #4070a0; }
code > span.st { color: #4070a0; }
code > span.co { color: #60a0b0; font-style: italic; }
code > span.ot { color: #007020; }
code > span.al { color: #ff0000; font-weight: bold; }
code > span.fu { color: #06287e; }
code > span.er { color: #ff0000; font-weight: bold; }
  </style>
</head>
<body>
<h1 id="test-6">test 6</h1>
<p>This file can be loaded into whatever editor you like to use for knitr. ghc is called for the second code block.</p>
<pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(knitr)
opts_chunk$<span class="kw">set</span>(<span class="dt">engine =</span> <span class="st">&quot;haskell&quot;</span>, <span class="dt">engine.path =</span> <span class="st">&quot;ghc&quot;</span>)</code></pre>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">:</span>set <span class="fu">-</span><span class="dt">XQuasiQuotes</span>
<span class="fu">:</span><span class="kw">module</span> <span class="fu">+</span><span class="dt">RlangQQ</span>
<span class="kw">let</span> fibs <span class="fu">=</span> <span class="fl">0.0</span><span class="fu">:</span><span class="dv">1</span><span class="fu">:</span> <span class="fu">zipWith</span> (<span class="fu">+</span>) fibs (<span class="fu">drop</span> <span class="dv">1</span> fibs)
[r<span class="fu">|</span> png(<span class="ch">&#39;test6_fig1.png&#39;</span>); plot(<span class="dv">1</span><span class="fu">:</span><span class="dv">20</span>, <span class="fu">$</span>(<span class="fu">take</span> <span class="dv">20</span> fibs)); dev<span class="fu">.</span>off() <span class="fu">|</span>]</code></pre>
<div class="figure">
<img src="test6_fig1.png" alt="test6 caption here" /><p class="caption">test6 caption here</p>
</div>
<h2 id="limitations">limitations</h2>
<ul>
<li>This simple example works but unfortunately the haskell knitr engine doesn't allow newlines instead of semicolons in the quasiquote (<code>[r| |]</code>)</li>
<li><p>Also note a comment from here <a href="http://yihui.name/knitr/demo/engines/"><code class="url">http://yihui.name/knitr/demo/engines/</code></a>:</p>
<pre><code>Except engine=&#39;R&#39; (default), all chunks are executed in separate sessions, so the variables cannot be directly shared. If we want to make use of objects created in previous chunks, we usually have to write them to files (as side effects). For the bash engine, we can use Sys.setenv() to export variables from R to bash (example).</code></pre></li>
<li><p>Graphical output from haskell chunks has to be manually included.</p></li>
</ul>
</body>
</html>