Skip to content
Browse files

use of environments rather than options in R

  • Loading branch information...
1 parent bf489aa commit 714ee597f81d024a93ff735229baf2ec6a65ef7b @cboettig committed Aug 30, 2012
Showing with 80 additions and 43 deletions.
  1. +28 −0 environments.Rmd
  2. +52 −0 environments.md
  3. +0 −43 math.html
View
28 environments.Rmd
@@ -0,0 +1,28 @@
+
+
+
+Instead of
+
+``` {r }
+options(FlickrKey = "XXXXXX-XXX-XXXX")
+key = getOption("FlickrKey")
+````
+
+
+We can use environments
+
+``` {r }
+Sys.setenv(FlickrKey = "XXXXXX-XXX-XXXX")
+key = Sys.getenv("FlickrKey")
+````
+
+Note that it seems the object needs to be a string (otherwise is coaxed into one):
+
+``` {r }
+f = function(x) 2*x
+b = 5
+Sys.setenv(test_function = f, a=b)
+Sys.getenv("test_function")
+class(g)
+Sys.getenv("a")
+````
View
52 environments.md
@@ -0,0 +1,52 @@
+
+
+
+Instead of
+
+
+```r
+options(FlickrKey = "XXXXXX-XXX-XXXX")
+key = getOption("FlickrKey")
+```
+
+
+
+We can use environments
+
+
+```r
+Sys.setenv(FlickrKey = "XXXXXX-XXX-XXXX")
+key = Sys.getenv("FlickrKey")
+```
+
+
+Note that it seems the object needs to be a string:
+
+
+```r
+f = function(x) 2 * x
+b = 5
+Sys.setenv(test_function = f, a = b, m = 5)
+Sys.getenv("test_function")
+```
+
+```
+## [1] "function (x) \n2 * x"
+```
+
+```r
+class(g)
+```
+
+```
+## [1] "character"
+```
+
+```r
+Sys.getenv("a", "m")
+```
+
+```
+## [1] "5"
+```
+
View
43 math.html
@@ -1,43 +0,0 @@
-<!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>
-</head>
-<body>
-<p>Add mathjax script right into the markdown file like so:</p>
-<p><code>html &lt;!-- Equations using MathJax --&gt; &lt;script type=&quot;text/javascript&quot; src=&quot;http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/x-mathjax-config&quot;&gt; MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: &quot;all&quot;} } }); &lt;/script&gt;</code></p>
-<!-- Equations using MathJax -->
-
-<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
-<p></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: &quot;all&quot;} } }); </script></p>
-<p>Add knitr block into the markdown file.</p>
-<p><code>r 1 + 1</code></p>
-<p><code>## [1] 2</code></p>
-<p>Display equations by delimiting with <code>&lt;div&gt;$$</code></p>
-<div>$$ J_\alpha(x) = \sum\limits_{m=0}^\infty \frac{(-1)^m}{m! \, \Gamma(m + \alpha + 1)}{\left({\frac{x}{2}}\right)}^{2 m + \alpha} $$</div>
-
-
-<p>And inline equations with <code>&lt;span&gt;$</code>, like <span>$e = mc^2$</span></p>
-<h3>Now the following works:</h3>
-<ul>
-<li>Pandoc generated latex: <code>pandoc -s math.md -o math.tex</code>.<br /></li>
-<li>The Markdown file will be converted to valid html by almost any markdown converter, which ignores the div/span elements. The mathjax script added in the top will cause these to display correctly. (Note this works for the inline equation too, even though <a href="http://www.mathjax.org/docs/2.0/start.html#tex-and-latex-input">mathjax says it shouldn't</a>?)</li>
-<li>To get pandoc to run in this mode without touching the math syntax, use <code>--strict</code> option: <code>pandoc -s --strict math.md -o math.html</code></li>
-<li>Pandoc can handle the mathjax rendering itself, since without <code>strict</code> enabled, it reads inside the div/span elements and finds math syntax it recognizes. as does <code>pandoc -s --mathjax math.md -o math3.html</code>. Likewise for mathml: <code>pandoc -s --mathml -o math4.html</code>.</li>
-<li>Simple html works too, though has no rendering engine: <code>pandoc -s math.md -o math2.html</code> so the result is not displayed properly.</li>
-</ul>
-<h3>See results</h3>
-<ul>
-<li><a href="https://github.com/cboettig/sandbox/blob/master/math.md">math.md</a></li>
-<li><a href="https://github.com/cboettig/sandbox/blob/master/math.tex">math.tex</a></li>
-<li>Pandoc strict (or most markdown intepreters): <a href="http://cboettig.github.com/sandbox/math3.html">math.html</a></li>
-<li>Pandoc mathjax: <a href="http://cboettig.github.com/sandbox/math3.html">math3.html</a></li>
-<li>mathml: <a href="http://cboettig.github.com/sandbox/math4.html">math4.html</a></li>
-<li>Pandoc's plain html: <a href="http://cboettig.github.com/sandbox/math2.html">math2.html</a></li>
-<li>Giving jekyll a copy of math.md, it creates <a href="http://cboettig.github.com/sandbox/math-jekyll.html">math-jekyll.html</a></li>
-</ul>
-</body>
-</html>

0 comments on commit 714ee59

Please sign in to comment.
Something went wrong with that request. Please try again.