packages feed

Rlang-QQ-0.2.0.0: examples/test7.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-7">test 7</h1>
<p>Same as test6, except needs a change to knitr as of October 2013 (ie. 1.5 is not good enough). <a href="https://github.com/yihui/knitr/pull/633">This commit is needed</a>.</p>
<p>This file can be loaded into whatever editor you like to use for knitr. I use <a href="http://www.vim.org/scripts/script.php?script_id=2628">vim-r-plugin</a>, but perhaps ESS or Rstudio can also work. After some set-up in the first block. 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>, <span class="dt">engine.opts =</span> <span class="st">&quot;-e </span><span class="ch">\&quot;</span><span class="st">:set -XQuasiQuotes</span><span class="ch">\&quot;</span><span class="st"> -e </span><span class="ch">\&quot;</span><span class="st">import RlangQQ</span><span class="ch">\&quot;</span><span class="st">&quot;</span>)</code></pre>
<pre class="sourceCode haskell"><code class="sourceCode haskell">
<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>
<pre class="sourceCode haskell"><code class="sourceCode haskell">
<span class="kw">do</span> <span class="kw">let</span> x <span class="fu">=</span> <span class="dv">1</span>
   <span class="fu">print</span>(<span class="dv">1</span><span class="fu">+</span>x)
   <span class="fu">print</span>(<span class="dv">2</span><span class="fu">+</span>x)</code></pre>
<pre><code>## 2
## 3</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><p>each block is a separate session. You would have to manually save/load variables defined in the previous chunk to make things work as they do for R.</p></li>
<li><p>code is interpreted, not compiled</p></li>
<li><p>graphical output from haskell chunks has to be manually included</p></li>
</ul>
<h2 id="raw-code">raw code</h2>
<p>See <a href="test7.Rmd.html">here</a></p>
</body>
</html>