What do I mean by reproducible research
- Being able to reproduce experiments
- Identify the state of the experiments (what has been done/what remains to be done)
- Understand the process which leads to the current state
Why using emacs ?
- Because you have all the tools to help you in this editor
Some pre-requisite
- Linux ubuntu 16.04 / bash
- Global informations
- EMACS = Editor MACroS
- Development started during the 70s
- Multiple variation GNU Emacs, XEmacs, AquaMacs…
- Compatible Unix-Like (Linux, macos, …) + windows
- Configuration = based on a dedicated language: emacs lisp
- Global key concepts
- 3 modifier keys = CTRL, MAJ, META
- META = alt on PC, command on MAC
- Commands = instructions to run. Can be associated with shortcuts!
- minibuffer: where commands are launched/messages are indicated
- 1 file: build.gradle
- 3 buffers: build.gradle, scratch, Messages
- scratch is a special buffer for scratch notes
- Messages is a special buffer which contains all the messages sent by emacs
- 3 windows: 1 at the top, 2 at the bottom
- 1 frame: emacs-bin@slemaguer-perso
- 1 minibuffer indicating the message “Beginning of buffer”
- Emacs adaptation = modes
- 2 kind of modes: major and minor
- 1 buffer = 1 major mode + N minor modes
- major mode = editing behavior (syntax coloring, indentation, …)
- minor mode = specific adaptations (matching parenthesis, spell/syntax checking, …)
- Help key = C-h m
- List all the mode enabled in the buffer + some documentation
- Example
- Global
- Configuration language = elisp (emacs lisp)
- Programming language ⇒ a little bit of investment....
- ....but powerful
- Entry point = ~/.emacs or ~/.emacs.d/init.el
- You can put everything there…
- Or import other files
- Not the focus of this course: a baseline configuration will be provided later
- Pre-configuration
- Package installation (ubuntu)
sudo apt-get install build-essential libglib2.0-dev imagemagick libgtk-3-dev libpoppler-dev libpoppler-glib-dev libxpm-dev libtiff-dev libjpeg-dev libgif-dev libncurses-dev
- Copy the following the following profile into ~/.profile : https://raw.githubusercontent.com/seblemaguer/emacs-reproducible-research/master/assets/configuration/profile
- For future use Adapt your bashrc by adding
# Include profile variables
source ~/.profile
- For the current session, write in the current terminal
source ~/.profile
echo $PATH # Check that the path is correct
- Compilation/installation
- Retrieve the installation shell script: https://raw.githubusercontent.com/seblemaguer/emacs-reproducible-research/master/assets/scripts/emacs_install.sh
- Execute the shell script with the following syntax
bash emacs_install.sh -j 2 $HOME/environment/local
- Running
emacs
- Emacs relies massively on shortcuts (but are not mandatory !)
- M-x = starting a command (that is the only mandatory one)
- C-h m (mode), C-h k (keys), C-h f (function) = documentation shortcut
- C-x f (open), C-x s (save), C-x w (save as) = open file/save buffer
- C-<space> (set/unset selection mark), M-w (copy), C-w (cut), C-y (paste)
- refcard = https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf
- Open some source code file (java, python, c, …)
- Open some tex file
- Query the documentation, …
- What is easy ?
- What is difficult ?
- Do you have an idea of how to improve
- Don’t hesitate to be exhaustive or say if you don’t understand something
- use-package = helper to install and configure a package
- URL = https://github.com/jwiegley/use-package/
- A baseline example
(use-package spaceline-all-the-icons ;; The package to install
:ensure t ;; Force the installation
:after spaceline ;; Initialisation after the given package
;; Preconfiguration, *before* the package is loaded
:init
(setq spaceline-all-the-icons-separator-type 'wave
spaceline-separator-dir-left '(left . left)
spaceline-separator-dir-right '(right . right)
spaceline-minor-modes-separator " ")
;; Configuration, *after* the package is loaded
:config
(spaceline-all-the-icons-theme)
(require 'spaceline-config)
(spaceline-helm-mode)
(use-package info+
:ensure t
:init
(spaceline-info-mode))
(use-package fancy-battery
:ensure t
:init
(add-hook 'after-init-hook #'fancy-battery-mode)
(display-battery-mode -1))
(spaceline-all-the-icons--setup-paradox)
)
- To list available packages use the command:
list-packages
- Retrieve the following file: https://raw.githubusercontent.com/seblemaguer/emacs-reproducible-research/master/assets/configuration/init.el
- Copy it into
~/.emacs.d/init.el
- Open emacs, it should look like that:
- Buffer management
- Using C-x C-b to open the ibuffer list
- File/directory management
- Using C-x C-r to list the recently opened files
- Using C-x C-d to list directories
- VC/Project management (see the next section)
- Main shortcut = <f4>
- Agenda management (see the section about org-mode)
- Main shortcut = <f12>
- Try to open some source code file (java, python, c, …)
- Try to open some tex file
- Try to query the documentation, …
- Try to spot the differences
- Why? because it’s faster :)
- How to:
- Retrieve the following shell script: https://raw.githubusercontent.com/seblemaguer/emacs-reproducible-research/master/assets/scripts/server_adapt.sh
- Execute the shell script with the following syntax
bash server_adapt.sh -j 2 $HOME/environment/local
- On the configuration part
- Uncomment the “server part” in the init.el file
- Try to run the emacs command
- Multiple tools available but we focus on projectile
- Repository = https://github.com/bbatsov/projectile
- Idea:
The concept of a project is pretty basic - just a folder containing special file. Currently git, mercurial, darcs and bazaar repos are considered projects by default. So are lein, maven, sbt, scons, rebar and bundler projects.
- Prefix : C-x p (see configuration file)
- Some useful commands
- C-c p f = open file in the project
- C-c p h = open helm to manipulate projectile
- DEMO
- Main tools is magit
- Repository = https://github.com/magit/magit
- Lots of avantages:
- All the functionality
- Easy to use
- Interface with github (magithub = https://github.com/vermiculus/magithub/)
- Entry command =
magit-status
- History of a file
- Tool = magit-timemachine
- Repository = https://github.com/pidu/git-timemachine
- Command =
git-timemachine
- DEMO
- DEMO
Org mode is for keeping notes, maintaining TODO lists, planning projects, and authoring documents with a fast and effective plain-text system.
- Also
- spreadsheet
- bibtex/reference
- …
- Summary = https://github.com/fniessen/refcard-org-mode
- C-c t = switch todo/done/… tags
- C-c C-d = define a deadline for the current task
- C-c C-s = schedule the current task
- Allows you to have a global view of the project in progress
- Command = org-dashboard-display
- Shortcut = <f4> d
- DEMO
- Allows you to visualize your “calendar”
- Command = org-agenda
- Shortcut = <f12>
- DEMO
- Allows to interrupt briefly your workflow to add a reminder in your global todolist
- To extend this nice feature, see section (Org-mode > Capturing) in the configuration file (~/.emacs.d/main.org)
- DEMO
- Summary = https://github.com/fniessen/refcard-org-mode
- For the meta-data
- “Minimum” header
#+TITLE: Reproducible with research with emacs (and org-mode)
#+AUTHOR: Sébastien Le Maguer
#+EMAIL: [email protected]
#+DATE: 12 May 2017
- Can be adapted for the output (Example Latex)
# ##############################################################################################################################
#+STARTUP: beamer
#+STARTUP: oddeven
#+LaTeX_CLASS: beamer
#+LaTeX_CLASS_OPTIONS: [9pt]
#+SELECT_TAGS: export
#+EXCLUDE_TAGS: noexport
#+BEAMER_THEME: progressbar
#+LATEX_CMD: xelatex
#+LaTeX_HEADER: \hypersetup{
#+LaTeX_HEADER: colorlinks = true,
#+LaTeX_HEADER: linkcolor = black
#+LaTeX_HEADER: }
#+latex_header: \usepackage{subfig}
#+LaTeX_HEADER: \usepackage{bibentry}
#+LaTeX_HEADER: \usepackage{multimedia}
#+LaTeX_HEADER: \makeatletter
#+LaTeX_HEADER: \let\@mycite\@cite
#+LaTeX_HEADER: \def\@cite#1#2{{\hypersetup{linkcolor=green!60!black}[{#1\if@tempswa , #2\fi}]}}
#+LaTeX_HEADER: \makeatother
# ##############################################################################################################################
- Summary = https://github.com/fniessen/refcard-org-mode
- Sections
* Header 1
** Header 2
*** Header 3
...
- Lists
- list 1
- list 11
+ list111 with other bullets
+ list112 with other bullets
- list 12
1. list121 as enumerate
2. list122 as enumarate
- Summary = https://github.com/fniessen/refcard-org-mode
- Text formatting
/Emphasize/ (italics), *strongly* (bold), and */very strongly/* (bold italics).
- Paragraph separated by an empty line
- Horizontal rule is done using 5 dashes
- Links are in brackets
- Mathematical formula exactly like latex :
\begin{equation}
f_1(x) = \frac{1}{N} \sum_{r=1}^R log(x(r)^2)
\end{equation}
\begin{equation} f_1(x) = \frac{1}{N} ∑r=1^R log(x(r)^2) \end{equation}
- Command = org-table-create
- Row separator = new line
- Column separator = “|”
- horizontal line = “|—+—|”
- ”|” = first/end column indicator
- ”-” = filler
- ”+” = column separator
#+CAPTION: (extracted from https://en.wikipedia.org/wiki/Getting_Things_Done)
#+NAME: fig:gtd
#+ATTR_HTML: :width 75%
#+ATTR_LATEX: :width 0.75\linewidth
[[./assets/images/GTDcanonical.png]]
- do you remember this slide “Task management - gtd principle” ?
- More complete information at = http://orgmode.org/orgcard.pdf
- In the text
- C-c C-l create a link
- Header
- C-<return> create an item at the same level of the current header (no list)
- M-<left/right-arrow> Change bullet and numbering type
- List
- M-<return> create an item at the same level in the list or header
- Shift-<left/right-arrow> Change bullet and numbering type
- In a table
- <pipe><hypen> followed by tab = create a table or complete the row
- Different kind of exporter (HTML, reveal, LaTeX, Beamer, Markdown, …)
- Command to export = C-c C-e then a dedicated buffer opens:
- DEMO
- Let’s try to write a small document
- Try to use everything we wrote before (a table, an image, …)
- Export it in latex and/or HTML
- Introduced by D. Knuth (FIXME: ref)
Literate programming is a programming paradigm introduced by Donald Knuth in which a program is given as an explanation of the program logic in a natural language, such as English, interspersed with snippets of macros and traditional source code, from which a compilable source code can be generated.
- org-babel is handling that
- Insert code using the following syntax
- Including a script file using the following syntax
#+include: "~/work/courses/current/teaching/reproducible-research/assets/files/example_src.org" src org :eval never-export
- Rendering results:
- org-babel is handling that
- Insert code using the following syntax
- Including a script file using the following syntax
#+include: "~/work/courses/current/teaching/reproducible-research/assets/files/example_src.org" src org :eval never-export
- Rendering results:
- Update the previous documents to add
- A source for which you just want to have the source visible in the exported document
- A source for which you just want to have the result visible in the exported document
- A source for which you want to have both the source and the result visible in the exported document
- Problem: how to deal with massive data/time consuming experiments?
- Solution:
- Design the experiments using workflow management tools (make, gradle, …)
- In the last experimental stage Format the results in a certain way (csv, ....)
- Design the org document assuming these results are available
- Call emacs to render the org-mode
- Preliminary informations:
- The default configuration is not used !
- An emacs configuration is embedded in the project
- Gradle is used to control the process
- Scripts are based on the one proposed in https://github.com/nhoffman/org-export
- repository = https://github.com/seblemaguer/example-gradle-emacs
. ├── build.gradle ├── gradle ├── gradlew ├── gradlew.bat ├── scripts │ ├── org-export-beamer.el │ ├── org-export-cli.el │ ├── org-export-html.el │ ├── org-export-latex.el │ └── org-export-reveal.el ├── settings.gradle └── src ├── assets ├── biblio.bib └── paper.org
- We provide....
- Gradle configuration (build.gradle, settings.gradle gradle*)
- Emacs exporter scripts (scripts/*.el)
- We need…
- the source of the document (src/paper.org)
- the optional bibliography (src/biblio.bib)
- the assets which are downloaded into src/assets
- The output will be put in the build directory
- see src/paper.org
- Nothing different than before except.....
- we assume the presence of the assets
- That is where the process is put into place
- First retrieve the assets
task downloadAssets(type: Download) {
src "http://www.coli.uni-saarland.de/~slemaguer/attachments/example_gradle_emacs/values.csv"
dest "src/assets/values.csv"
overwrite false
}
- Then process the assets
task processAssetsLatex(type: Copy) {
from fileTree('src').include('assets/**')
into "$buildDir/${rootProject.name}/latex"
}
- Finally generate the document (latex in this example)
task org2latex(type: Exec, dependsOn: "processAssetsLatex") {
def orgFile = file("src/slides.org")
def pdfFile = file("$buildDir/${rootProject.name}/latex/index.pdf")
inputs.files orgFile, processAssetsLatex
outputs.files pdfFile
commandLine "emacs-bin", "-q", "--no-site-file", "--evaluate", "--script", "scripts/org-export-beamer.el", "--infile", orgFile, "--outfile", pdfFile
}
- To run just run the following command:
./gradlew b
- Your turn:
- create a project based on the current one
- Try to generate some documentation
- (Quick) Introduction to emacs
- Main concepts: buffer, files, windows, commands, …
- Main commands: M-x, C-h m, C-h k, …
- Package management
- A baseline configuration ⇒ you can modify it :D
- (Quick) Introduction to org-mode
- Todo lists + Agenda management
- Writing documents using org-mode
- Exporting documents using org-mode
- Reproducible research
- Litterate programming with org-mode
- Invocating org-mode to generate documentation from a project
- Emacs - official
- The official website: https://www.gnu.org/software/emacs/
- The official manual: https://www.gnu.org/software/emacs/manual/html_node/emacs/index.html
- An introduction to elisp: https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html
- The official elisp manual: https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html
- The official emacs FAQ: https://www.gnu.org/software/emacs/manual/html_node/efaq/index.html
- Org mode - official
- The official website: http://orgmode.org/
- The official manual: http://orgmode.org/manual/
- A nice cookbook: http://ehneilsen.net/notebook/orgExamples/org-examples.html
- Some other interesting places
- emacswiki: https://www.emacswiki.org
- stackexchange: https://emacs.stackexchange.com
- reddit: https://www.reddit.com/r/emacs/
- Channels (IRC, on irc.freenode.net):
- #emacs
- #emacs-beginners
- #org-mode
- Some advices
- Learning is trying and then using (especially for the shortcuts)
- Think about the ratio saving up now/saving up later