Skip to content
Snippets Groups Projects
Commit bfb3ca4a authored by Jonathan Hartman's avatar Jonathan Hartman
Browse files

Started a section on code cells

parent 4434b71b
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,10 @@ Let’s make an executive summary of org-mode:
Org-mode is a magnificent tool when it comes to reproducible research [^1], since this combines a
well documented way of analysing a data set.
By combining org-mode with code, we can create a document which not only describes and explains
a process or analysis in the style of literate programming, but also can be automatically run to
generate nicely formatted files run on the most recently available data.
[^1]: Stanisic, Luka, and Arnaud Legrand. 2014. “Effective Reproducible Research with Org-Mode
and Git.” In /Euro-Par 2014: Parallel Processing Workshops/, edited by Luís Lopes, Julius
Žilinskas, Alexandru Costan, Roberto G. Cascella, Gabor Kecskemeti, Emmanuel Jeannot, Mario
......@@ -56,8 +60,67 @@ Cannataro, et al., 475–86. Cham: Springer International Publishing.
### How to write a Code Cell
- syntax
- optional parameters
Code blocks in org-babel always start and end the same way:
```
#+BEGIN_SRC <language>
#+END_SRC
```
We can also add plenty of metadata before the block:
- `#+NAME` Provides the block with a name, so that we can easily reference it from other code cells
- `#+CAPTION` Provide a caption under the cell when the document is exported
There are also switches we can add after the language that affect how the cell is executed or
processed:
- `:results` Controls how the results of the code execution are handled.
- `:results output` outputs the results of the cell in the document
- `:results silent`supresses all output from the cell
- `:results file` creates a file to contain the output
- `:exports` Controls how the code block itself is treated in the document.
- `:exports code` includes the code block itself in the document
- `:exports results` supresses the code, but shows any results generated by the code
- `:exports both` includes both the code and the results in the document
- `:eval`
- `:eval yes` The code cell will be evaluated when the document is exported
- `:eval no` The code cell will not be evaluated when the document is exported. You might use
this when
- `:eval no-export` The code will not be evaluated when exporting, but will execute within the
org-mode buffer
- `:tangle yes` The code in this block will be "tangled" (extracted) into a seperate source file.
This could be useful if you are documenting how to create a script and part of the result of the
document is the final script itself.
There are some additional switches we can add that are specific to the language used in the cell.
For example:
- In Python or R, we can use the `:session <name>` switch to ensure more than one code block share
a session
- In R, we can use `:colnames yes` or `:colnames no` to dictate whether or not column names should
appear in the results. There is a similar switch called `:rownames`
### Variables
We can use `var=<value>` to set a variable that will be available in the code block. This variable
can either be a constant or a reference to another cell's `#+NAME`, in which case the value of the
variable will be set to whatever the result of that cell is.
# Preparing Data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment