Commit 775dfe80 authored by Arnaud Legrand's avatar Arnaud Legrand

Initial import from github resources

parent de8e1799
This diff is collapsed.
# -*- mode: org -*-
#+TITLE: Rstudio
#+AUTHOR: Arnaud Legrand
#+DATE: June, 2018
#+STARTUP: overview indent
* Table of Contents :TOC:
- [[#interacting-with-gitlab][Interacting with gitlab]]
- [[#additional-jupyter-resources-or-tricks][Additional Jupyter resources or tricks]]
- [[#tips-and-tricks][Tips and tricks]]
- [[#running-r-and-python-in-the-same-notebook][Running R and Python in the same notebook]]
- [[#exporting-a-notebook][Exporting a notebook]]
- [[#installing-jupyter-or-jupyter-hub-on-your-own-machine][Installing jupyter or jupyter hub on your own machine]]
- [[#installing-jupyter][Installing jupyter]]
- [[#using-r][Using R]]
- [[#exporting-your-notebooks-with-latex][Exporting your notebooks with latex]]
- [[#interacting-with-gitlab][Interacting with gitlab]]
- [[#interesting-extensions][Interesting extensions]]
- [[#installing-jupyterhub][Installing jupyterhub]]
* Interacting with gitlab
#+BEGIN_QUOTE
This section needs some love.
#+END_QUOTE
As you may have seen from the videos, we provide two buttons to sync
with gitlab. Indeed, even if you recover your files when you log back
into fun, the jupyter runs on a different machine than the gitlab
server and you need to commit your notebook every time you have made a
significant step. This is also the only way to really make it public
and to share your notebook with others.
* Additional Jupyter resources or tricks
** Tips and tricks
The following [[https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/][webpage]] lists several Jupyter tricks (in particular, it
illustrates many =Ipython magic= commands) that should improve your
efficiency (note that this blog post is about two years old so some of
the tricks may have been integrated in the default behavior of jupyter
now).
** Running R and Python in the same notebook
The best solution to this is to install rpy2. On my machine, I have
installed the =python3-rpy2= debian package with =apt-get install=. An
other alternative consists in going through the python package manager
with
#+begin_src python :results output :exports both
pip install rpy2
#+end_src
Then you'll be able to use both languages in the same notebook by:
1. Loading =rpy2=:
#+begin_src python :results output :exports both
%load_ext rpy2.ipython
#+end_src
2. Using the =%R= Ipython magic:
#+begin_src python :results output :exports both
%R
summary(cars)
#+end_src
Python objects can then even be passed to R as follows (assuming df
is a pandas dataframe:
#+begin_src python :results output :exports both
%%R -i df
plot((df)
#+end_src
** Exporting a notebook
Obviously, you can convert to html or pdf using the using the =File >
Download as > HTML= (or =PDF=) menu option. This can also be done from
the command line with the following command:
#+begin_src sh :results output :exports both
ipython3 nbconvert --to pdf Untitled.ipynb
#+end_src
If you want to use a specific style, then the nbconvert exporter
should be customised. This is discussed and demoed [[http://markus-beuckelmann.de/blog/customizing-nbconvert-pdf.html][here]]. We encourage
you to simply read the [[https://nbconvert.readthedocs.io/en/latest/][doc of nbconvert]].
Instead of going directly through LaTeX and playing too much with the
nbconvert exporter, an other option consists in exporting to Markdown
and playing with [[https://pandoc.org/][pandoc]]. Both approaches work, it's rather a matter of
taste.
* Installing jupyter or jupyter hub on your own machine
** Installing jupyter
Here is what you should install:
#+begin_src shell :results output :exports both
sudo apt-get install jupyter-notebook python3-pip python3-matplotlib python3-numpy
#+end_src
On my machine, I got the version 5.4.1:
#+begin_src shell :results output :exports both
jupyter-notebook --version
#+end_src
#+RESULTS:
: 5.4.1
The ipython notebook can then be run with the following command:
#+begin_src shell :results output :exports both
jupyter-notebook
#+end_src
** Using R
If you also want to have the R kernel in jupyter, follow [[https://github.com/IRkernel/IRkernel#installation][these
instructions]].
Alternatively, you can install =rpy2= (see the [[*Running R and Python in the same notebook][Running R and Python in
the same notebook]] section).
#+begin_src shell :results output :exports both
sudo apt-get python3-rpy2
#+end_src
** Exporting your notebooks with latex
Here is what I had to install to make sure the notebook export via
latex works:
#+begin_src shell :results output :exports both
sudo apt-get install wkhtmltopdf
sudo apt-get install texlive-xetex
#+end_src
** Interacting with gitlab
Here is our [[https://github.com/brospars/nb-git][jupyter extension that allows to git push/pull from the
notebooks]]:
#+begin_src shell :results output :exports both
jupyter nbextension install https://raw.githubusercontent.com/brospars/nb-git/master/nb-git.js
jupyter nbextension enable nb-git
#+end_src
** Interesting extensions
- [[https://stackoverflow.com/questions/33159518/collapse-cell-in-jupyter-notebook][Code folding]]
#+begin_src shell :results output :exports both
pip3 install jupyter_contrib_nbextensions
# jupyter contrib nbextension install --user # not done yet
#+end_src
- [[https://github.com/kirbs-/hide_code][Hiding code]]
#+begin_src sh :results output :exports both
sudo pip3 install hide_code
sudo jupyter-nbextension install --py hide_code
jupyter-nbextension enable --py hide_code
jupyter-serverextension enable --py hide_code
#+end_src
** Installing jupyterhub
#+BEGIN_QUOTE
Benoit may give a few hints on this.
#+END_QUOTE
ARCHIVE=replicable_article
# ARCHIVE_FILES=$(shell git ls-tree -r master --name-only | grep -v -e 'article.pdf')
ARCHIVE_FILES=article.org biblio.bib Makefile
all: article.pdf
%.tex: %.org
emacs -q -batch --eval "(setq enable-local-eval t)" --eval "(setq enable-local-variables t)" $^ --funcall org-latex-export-to-latex
%.pdf: %.tex
pdflatex $^
bibtex `basename $^ .tex`
pdflatex $^
pdflatex $^
%.html: %.org
emacs -q -batch --eval "(setq enable-local-eval t)" --eval "(setq enable-local-variables t)" $^ --funcall org-html-export-to-html
$(ARCHIVE).tgz: $(ARCHIVE_FILES)
tar --xform "s|^|$(ARCHIVE)/|" -zcf $@ $^
clean:
rm -f article.aux article.bbl article.blg article.log article.out *~
distclean: clean
rm -f article.html article.tex article.pdf figure.pdf data.csv measurements.txt IEEEtran.bst IEEEtran.cls \#article.org\#
This diff is collapsed.
@article{schulte11:_activ_docum_org_mode,
author ={Eric Schulte and Dan Davison},
title ={Active Document with Org-Mode},
journal ={Computing in Science \& Engineering},
year =2011,
volume =13,
number =3,
pages ={66--73},
month ={May/June}
}
@Article{PER-GRA:2007,
Author = {P\'erez, Fernando and Granger, Brian E.},
Title = {{IP}ython: a System for Interactive Scientific Computing},
Journal = {Computing in Science and Engineering},
Volume = {9},
Number = {3},
Pages = {21--29},
month = may,
year = 2007,
url = "http://ipython.org",
ISSN = "1521-9615",
doi = {10.1109/MCSE.2007.53},
publisher = {IEEE Computer Society},
}
@article{qsort,
author = {Hoare, C. A. R.},
title = {Algorithm 64: Quicksort},
journal = {Commun. ACM},
issue_date = {July 1961},
volume = {4},
number = {7},
month = jul,
year = {1961},
issn = {0001-0782},
pages = {321--},
url = {http://doi.acm.org/10.1145/366622.366644},
doi = {10.1145/366622.366644},
acmid = {366644},
publisher = {ACM},
address = {New York, NY, USA},
}
Size: 100
Sequential quicksort took: 0.000010 sec.
Parallel quicksort took: 0.004024 sec.
Built-in quicksort took: 0.000013 sec.
Size: 100
Sequential quicksort took: 0.000010 sec.
Parallel quicksort took: 0.004448 sec.
Built-in quicksort took: 0.000014 sec.
Size: 100
Sequential quicksort took: 0.000009 sec.
Parallel quicksort took: 0.003384 sec.
Built-in quicksort took: 0.000013 sec.
Size: 100
Sequential quicksort took: 0.000010 sec.
Parallel quicksort took: 0.003738 sec.
Built-in quicksort took: 0.000012 sec.
Size: 100
Sequential quicksort took: 0.000010 sec.
Parallel quicksort took: 0.003133 sec.
Built-in quicksort took: 0.000011 sec.
Size: 1000
Sequential quicksort took: 0.000128 sec.
Parallel quicksort took: 0.020407 sec.
Built-in quicksort took: 0.000209 sec.
Size: 1000
Sequential quicksort took: 0.000126 sec.
Parallel quicksort took: 0.022003 sec.
Built-in quicksort took: 0.000201 sec.
Size: 1000
Sequential quicksort took: 0.000128 sec.
Parallel quicksort took: 0.016149 sec.
Built-in quicksort took: 0.000210 sec.
Size: 1000
Sequential quicksort took: 0.000128 sec.
Parallel quicksort took: 0.014594 sec.
Built-in quicksort took: 0.000209 sec.
Size: 1000
Sequential quicksort took: 0.000129 sec.
Parallel quicksort took: 0.014905 sec.
Built-in quicksort took: 0.000210 sec.
Size: 10000
Sequential quicksort took: 0.001774 sec.
Parallel quicksort took: 0.018943 sec.
Built-in quicksort took: 0.001720 sec.
Size: 10000
Sequential quicksort took: 0.001698 sec.
Parallel quicksort took: 0.016226 sec.
Built-in quicksort took: 0.001733 sec.
Size: 10000
Sequential quicksort took: 0.001652 sec.
Parallel quicksort took: 0.017348 sec.
Built-in quicksort took: 0.001702 sec.
Size: 10000
Sequential quicksort took: 0.001680 sec.
Parallel quicksort took: 0.017302 sec.
Built-in quicksort took: 0.001726 sec.
Size: 10000
Sequential quicksort took: 0.001675 sec.
Parallel quicksort took: 0.017386 sec.
Built-in quicksort took: 0.001716 sec.
Size: 100000
Sequential quicksort took: 0.020040 sec.
Parallel quicksort took: 0.050548 sec.
Built-in quicksort took: 0.020300 sec.
Size: 100000
Sequential quicksort took: 0.020004 sec.
Parallel quicksort took: 0.043119 sec.
Built-in quicksort took: 0.020504 sec.
Size: 100000
Sequential quicksort took: 0.019763 sec.
Parallel quicksort took: 0.050735 sec.
Built-in quicksort took: 0.020439 sec.
Size: 100000
Sequential quicksort took: 0.019913 sec.
Parallel quicksort took: 0.049806 sec.
Built-in quicksort took: 0.020541 sec.
Size: 100000
Sequential quicksort took: 0.019726 sec.
Parallel quicksort took: 0.044636 sec.
Built-in quicksort took: 0.020252 sec.
Size: 1000000
Sequential quicksort took: 0.230648 sec.
Parallel quicksort took: 0.162221 sec.
Built-in quicksort took: 0.242869 sec.
Size: 1000000
Sequential quicksort took: 0.235778 sec.
Parallel quicksort took: 0.162137 sec.
Built-in quicksort took: 0.241607 sec.
Size: 1000000
Sequential quicksort took: 0.238383 sec.
Parallel quicksort took: 0.163279 sec.
Built-in quicksort took: 0.242786 sec.
Size: 1000000
Sequential quicksort took: 0.232921 sec.
Parallel quicksort took: 0.170237 sec.
Built-in quicksort took: 0.241583 sec.
Size: 1000000
Sequential quicksort took: 0.230096 sec.
Parallel quicksort took: 0.153896 sec.
Built-in quicksort took: 0.242492 sec.
(require 'org-install)
(require 'org)
(setq inhibit-splash-screen t)
(setq frame-title-format
'("Emacs - " (buffer-file-name "%f"
(dired-directory dired-directory "%b"))))
(global-font-lock-mode t)
(custom-set-faces
'(flyspell-incorrect ((t (:inverse-video t)))))
(line-number-mode 1)
(column-number-mode 1)
(load-library "paren")
(show-paren-mode 1)
(transient-mark-mode t)
(require 'paren)
(defalias 'yes-or-no-p 'y-or-n-p)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(setq
ns-command-modifier 'meta ; Apple/Command key is Meta
ns-alternate-modifier nil ; Option is the Mac Option key
ns-use-mac-modifier-symbols nil ; display standard Emacs (and not standard Mac) modifier symbols
)
(cua-mode t)
(defun jump-mark ()
(interactive)
(set-mark-command (point)))
(defun beginning-of-defun-and-mark ()
(interactive)
(push-mark (point))
(beginning-of-defun))
(defun end-of-defun-and-mark ()
(interactive)
(push-mark (point))
(end-of-defun))
(global-set-key "\^c\^b" 'beginning-of-defun-and-mark)
(global-set-key "\^c\^e" 'end-of-defun-and-mark)
(global-set-key "\^c\^j" 'jump-mark)
(global-set-key [S-f6] 'jump-mark) ;; jump from mark to mark
(global-set-key "\M-g" 'goto-line)
(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
;; C-x C-0 restores the default font size
;; Inspired from http://tex.stackexchange.com/questions/166681/changing-language-of-flyspell-emacs-with-a-shortcut
;; (defun spell (choice)
;; "Switch between language dictionaries."
;; (interactive "cChoose: (a) American | (f) Francais")
;; (cond ((eq choice ?1)
;; (setq flyspell-default-dictionary "american")
;; (setq ispell-dictionary "american")
;; (ispell-kill-ispell))
;; ((eq choice ?2)
;; (setq flyspell-default-dictionary "francais")
;; (setq ispell-dictionary "francais")
;; (ispell-kill-ispell))
;; (t (message "No changes have been made."))) )
(define-key global-map (kbd "C-c s a") (lambda () (interactive) (ispell-change-dictionary "american")))
(define-key global-map (kbd "C-c s f") (lambda () (interactive) (ispell-change-dictionary "francais")))
(define-key global-map (kbd "C-c s r") 'flyspell-region)
(define-key global-map (kbd "C-c s b") 'flyspell-buffer)
(define-key global-map (kbd "C-c s s") 'flyspell-mode)
(global-set-key [f5] '(lambda () (interactive) (revert-buffer nil t nil)))
(defun auto-fill-mode-on () (TeX-PDF-mode 1))
(add-hook 'tex-mode-hook 'TeX-PDF-mode-on)
(add-hook 'latex-mode-hook 'TeX-PDF-mode-on)
(setq TeX-PDF-mode t)
(defun auto-fill-mode-on () (auto-fill-mode 1))
(add-hook 'text-mode-hook 'auto-fill-mode-on)
(add-hook 'emacs-lisp-mode 'auto-fill-mode-on)
(add-hook 'tex-mode-hook 'auto-fill-mode-on)
(add-hook 'latex-mode-hook 'auto-fill-mode-on)
(setq org-directory "~/org/")
(setq org-hide-leading-stars t)
(setq org-alphabetical-lists t)
(setq org-src-fontify-natively t) ;; you want this to activate coloring in blocks
(setq org-src-tab-acts-natively t) ;; you want this to have completion in blocks
(setq org-hide-emphasis-markers t) ;; to hide the *,=, or / markers
(setq org-pretty-entities t) ;; to have \alpha, \to and others display as utf8 http://orgmode.org/manual/Special-symbols.html
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-capture)
(global-set-key (kbd "C-c a") 'org-agenda)
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map (kbd "C-c a") 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(setq org-default-notes-file "~/org/notes.org")
(define-key global-map "\C-cd" 'org-capture)
(setq org-capture-templates (quote (("t" "Todo" entry (file+headline "~/org/liste.org" "Tasks") "* TODO %?
%i
%a" :prepend t) ("j" "Journal" entry (file+datetree "~/org/journal.org") "* %?
Entered on %U
%i
%a"))))
(setq org-agenda-include-all-todo t)
(setq org-agenda-include-diary t)
(global-set-key (kbd "C-c d") 'insert-date)
(defun insert-date (prefix)
"Insert the current date. With prefix-argument, use ISO format. With
two prefix arguments, write out the day and month name."
(interactive "P")
(let ((format (cond
((not prefix) "** %Y-%m-%d")
((equal prefix '(4)) "[%Y-%m-%d]"))))
(insert (format-time-string format))))
(global-set-key (kbd "C-c t") 'insert-time-date)
(defun insert-time-date (prefix)
"Insert the current date. With prefix-argument, use ISO format. With
two prefix arguments, write out the day and month name."
(interactive "P")
(let ((format (cond
((not prefix) "[%H:%M:%S; %d.%m.%Y]")
((equal prefix '(4)) "[%H:%M:%S; %Y-%m-%d]"))))
(insert (format-time-string format))))
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c <up>") 'outline-up-heading)
(global-set-key (kbd "C-c <left>") 'outline-previous-visible-heading)
(global-set-key (kbd "C-c <right>") 'outline-next-visible-heading)
;; In org-mode 9 you need to have #+PROPERTY: header-args :eval never-export
;; in the beginning or your document to tell org-mode not to evaluate every
;; code block every time you export.
(setq org-confirm-babel-evaluate nil) ;; Do not ask for confirmation all the time!!
(org-babel-do-load-languages
'org-babel-load-languages
'(
(shell . t)
(python . t)
(R . t)
(ruby . t)
(ocaml . t)
(ditaa . t)
(dot . t)
(octave . t)
(sqlite . t)
(perl . t)
(screen . t)
(plantuml . t)
(lilypond . t)
(org . t)
(makefile . t)
))
(setq org-src-preserve-indentation t)
(add-to-list 'org-structure-template-alist
'("s" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("m" "#+begin_src emacs-lisp :tangle init.el\n\n#+end_src" "<src lang=\"emacs-lisp\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("r" "#+begin_src R :results output :session *R* :exports both\n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("R" "#+begin_src R :results output graphics :file (org-babel-temp-file \"figure\" \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("RR" "#+begin_src R :results output graphics :file (org-babel-temp-file (concat (file-name-directory (or load-file-name buffer-file-name)) \"figure-\") \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("p" "#+begin_src python :results output :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("P" "#+begin_src python :results output :session *python* :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("PP" "#+begin_src python :results file :var matplot_lib_filename=(org-babel-temp-file \"figure\" \".png\") :exports both \nimport matplotlib.pyplot as plt\n\nimport numpy\nx=numpy.linspace(-15,15)\nplt.figure(figsize=(10,5))\nplt.plot(x,numpy.cos(x)/x)\nplt.tight_layout()\n\nplt.savefig(matplot_lib_filename)\nreturn(matplot_lib_filename)\n#+end_src" "<src lang=\"python\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("b" "#+begin_src shell :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("B" "#+begin_src shell :session *shell* :results output :exports both \n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
'("g" "#+begin_src dot :results output graphics :file \"/tmp/graph.pdf\" :exports both
digraph G {
node [color=black,fillcolor=white,shape=rectangle,style=filled,fontname=\"Helvetica\"];
A[label=\"A\"]
B[label=\"B\"]
A->B
}\n#+end_src" "<src lang=\"dot\">\n\n</src>"))
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
(add-hook 'org-mode-hook 'org-display-inline-images)
(add-hook 'org-mode-hook 'org-babel-result-hide-all)
This diff is collapsed.
# -*- mode: org -*-
# -*- coding: utf-8 -*-
#+STARTUP: overview indent inlineimages logdrawer
#+TITLE: Journal
#+AUTHOR: Put your name here
#+LANGUAGE: en
#+TAGS: LIG(L) HOME(H) Europe(E) Blog(B) noexport(n) Stats(S)
#+TAGS: Epistemology(E) Vulgarization(V) Teaching(T) R(R) OrgMode(O) Python(P)
#+EXPORT_SELECT_TAGS: Blog
#+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+COLUMNS: %25ITEM %TODO %3PRIORITY %TAGS
#+SEQ_TODO: TODO(t!) STARTED(s!) WAITING(w@) APPT(a!) | DONE(d!) CANCELLED(c!) DEFERRED(f!)
* 2018
** 2018-02 March
*** 2018-02-12 Monday
**** Demonstrating Emacs/Orgmode shortcuts
These informations were gathered and first demonstrated in my [[https://github.com/alegrand/RR_webinars/blob/master/1_replicable_article_laboratory_notebook/index.org][First
webinar on reproducible research: litterate programming]].
***** Emacs shortcuts
Here are a few convenient emacs shortcuts for those that have never
used emacs. In all of the emacs shortcuts, =C=Ctrl=, =M=Alt/Esc= and
=S=Shift=. Note that you may want to use two hours to follow the emacs
tutorial (=C-h t=). In the configuration file CUA keys have been
activated and allow you to use classical copy/paste (=C-c/C-v=)
shortcuts. This can be changed from the Options menu.
- =C-x C-c= exit
- =C-x C-s= save buffer
- =C-g= panic mode ;) type this whenever you want to exit an awful
series of shortcuts
- =C-Space= start selection marker although selection with shift and
arrows should work as well
- =C-l= reposition the screen
- =C-_= (or =C-z= if CUA keys have been activated)
- =C-s= search
- =M-%= replace
- =C-x C-h= get the list of emacs shortcuts
- =C-c C-h= get the list of emacs shortcuts considering the mode you are
currently using (e.g., C, Lisp, org, ...)
There are a bunch of cheatsheets also available out there (e.g.,
[[http://www.shortcutworld.com/en/linux/Emacs_23.2.1.html][this one for emacs]] and [[http://orgmode.org/orgcard.txt][this one for org-mode]] or this [[http://sachachua.com/blog/wp-content/uploads/2013/05/How-to-Learn-Emacs-v2-Large.png][graphical one]]).
***** Org-mode
Many emacs shortcuts start by =C-x=. Org-mode's shortcuts generaly
start with =C-c=.
- =Tab= fold/unfold
- =C-c c= capture (finish capturing with =C-c C-c=, this is explained on
the top of the buffer that just opened)
- =C-c C-c= do something useful here (tag, execute, ...)
- =C-c C-o= open link
- =C-c C-t= switch todo
- =C-c C-e= export
- =M-Enter= new item/section
- =C-c a= agenda (try the =L= option)
- =C-c C-a= attach files
- =C-c C-d= set a deadl1ine (use =S-arrows= to navigate in the dates)
- =A-arrows= move subtree (add shift for the whole subtree)
***** Org-mode Babel (for literate programming)
- =<s + tab= template for source bloc. You can easily adapt it to get
this:
#+BEGIN_EXAMPLE
#+begin_src shell
ls
#+end_src
#+END_EXAMPLE
Now if you =C-c C-c=, it will execute the block.
#+BEGIN_EXAMPLE
#+RESULTS:
| #journal.org# |
| journal.html |
| journal.org |
| journal.org~ |
#+END_EXAMPLE
- Source blocks have many options (formatting, arguments, names,
sessions,...), which is why I have my own shortcuts =<b + tab= bash
block (or =B= for sessions).
#+BEGIN_EXAMPLE
#+begin_src shell :results output :exports both
ls /tmp/*201*.pdf
#+end_src
#+RESULTS:
: /tmp/2015_02_bordeaux_otl_tutorial.pdf
: /tmp/2015-ASPLOS.pdf
: /tmp/2015-Europar-Threadmap.pdf
: /tmp/europar2016-1.pdf
: /tmp/europar2016.pdf
: /tmp/M2-PDES-planning-examens-janvier2016.pdf
#+END_EXAMPLE
- I have defined many such templates in my configuration. You can
give a try to =<r=, =<R=, =<RR=, =<g=, =<p=, =<P=, =<m= ...
- Some of these templates are not specific to babel: e.g., =<h=, =<l=,
=<L=, =<c=, =<e=, ...
# -*- mode: org -*-
#+TITLE: Rstudio
#+AUTHOR: Arnaud Legrand
#+DATE: June, 2018
#+STARTUP: overview indent
* Table of Contents :TOC:
- [[#installing-rstudio][Installing Rstudio]]
- [[#linux-debian-ubuntu][Linux (debian, ubuntu)]]
- [[#mac-osx-and-windows][Mac OSX and Windows]]
- [[#installing-git][Installing Git]]
- [[#linux-debian-ubuntu][Linux (debian, ubuntu)]]
- [[#mac-osx-and-windows][Mac OSX and Windows]]
- [[#rstudio-and-gitgithubgitlab][Rstudio and git/github/gitlab]]
- [[#cheat-sheets][Cheat Sheets]]
* Installing Rstudio
** Linux (debian, ubuntu)
We provide here only instructions for debian-based distributions. Feel
free to contribute to this document to provide up-to-date information
for other distributions (e.g.n redhat, fedora).
Today, the stable versions of the most common distributions provide
recent enough versions of emacs and org-mode:
- Debian (stretch) ships with [[https://packages.debian.org/stretch/r-base][R 3.3.3-1]], [[https://packages.debian.org/stretch/r-cran-knitr][knitr 1.15.1]], and [[https://packages.debian.org/stretch/r-cran-ggplot2][ggplot 2.2.1]]
- Ubuntu (bionic 18.04) ships with [[https://packages.ubuntu.com/bionic/r-base][R 3.4.4]], and [[https://packages.ubuntu.com/bionic/r-cran-knitr][knitr 1.17]], and [[https://packages.ubuntu.com/bionic/r-cran-ggplot2][ggplot 2.2.1]]
- Ubuntu (artful 17.04) ships with [[https://packages.ubuntu.com/artful/r-base][R 3.4.2]], and [[https://packages.ubuntu.com/artful/r-cran-knitr][knitr 1.15]], and [[https://packages.ubuntu.com/artful/r-cran-ggplot2][ggplot 2.2.1]]
If your distribution is older than this, well, it may be a good time
for upgrading...
*** Installing R
Beforehand, you need to install the R language and convenient packages
by running (as root):
#+BEGIN_SRC shell
apt-get update ; sudo apt-get install r-base r-cran-knitr r-cran-ggplot2
#+END_SRC
Alternatively, if the installation of =r-cran-gplot2= or =r-cran-knitr=
fails, you may want to install them locally (through the R packaging
system) and manually by running the following commands in R (or
Rstudio):
#+BEGIN_SRC R
install.packages("knitr")
install.packages("ggplot2")
#+END_SRC
If you plan to export pdf documents with LaTeX, you probably also want
to run (as root):
#+begin_src sh :results output :exports both
apt-get update ; apt-get install texlive-base
#+end_src
*** Installing rstudio
Rstudio is unfortunately not packaged within debian so the easiest is
to download the corresponding debian package on the [[https://www.rstudio.com/products/rstudio/download/#download][Rstudio webpage]]
and then to install it manually (depending on when you do this, you
can obviously change the version number). Here is how to install it:
#+BEGIN_SRC shell
cd /tmp/
wget https://download1.rstudio.org/rstudio-xenial-1.1.453-amd64.deb
sudo dpkg -i rstudio-xenial-1.1.453-amd64.deb
sudo apt-get update ; sudo apt-get -f install # to fix possibly missing dependencies
#+END_SRC
** Mac OSX and Windows
#+BEGIN_QUOTE
Some instructions on installing R and knitr must be missing. This
should be tested and improved.
#+END_QUOTE
Download and install rstudio from the [[https://www.rstudio.com/products/rstudio/download/#download][Rstudio webpage]] by choosing the
right operating system.
Then open Rstudio and type the following commands in the console to
install knitr and ggplot2:
#+BEGIN_SRC R
install.packages("knitr")
install.packages("ggplot2")
#+END_SRC
* Installing Git
** Linux (debian, ubuntu)
We provide here only instructions for debian-based distributions. Feel
free to contribute to this document to provide up-to-date information
for other distributions (e.g.n redhat, fedora).
Run (as root):
#+begin_src sh :results output :exports both
apt-get update ; apt-get install git
#+end_src
** Mac OSX and Windows
- Download and install Git from the [[https://git-scm.com/downloads][Git website]].
- Optional Git clients (should not be needed if you work within
Rstudio):
- [[https://www.sourcetreeapp.com/][SourceTree]]
- [[github desktop][GitHub Desktop]]
#+BEGIN_QUOTE
[[https://github.com/desktop/desktop/issues/852][Apparently]], this works with gitlab and https.
#+END_QUOTE
* Rstudio and git/github/gitlab
#+BEGIN_QUOTE
We may want to redo a screencast in French for this
#+END_QUOTE
- [[https://www.rstudio.com/resources/webinars/rstudio-essentials-webinar-series-managing-part-2/][This video on using git/githugb/gitlab from Rstudio]] (starting at time 9:09)
Alternatively, we can point to:
http://www.geo.uzh.ch/microsite/reproducible_research/post/rr-rstudio-git/
- Part 1/item 2: Setup Git in RStudio
- Part 2 (to adapt to gitlab)
- Part 3
* Cheat Sheets
The Rstudio team has created a lot of good material and tutorials. You
should definitively look at the [[https://www.rstudio.com/resources/cheatsheets/][Cheat sheets webpage]]. In particular
you want to have look at the ones on:
- [[https://github.com/rstudio/cheatsheets/raw/master/rstudio-ide.pdf][the Rstudio IDE]],
- [[https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf][R Markdown]],
- the [[https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf][R Markdown Reference guide]],
- [[https://github.com/rstudio/cheatsheets/raw/master/data-visualization-2.1.pdf][data visualization with ggplot2]],
- [[https://github.com/rstudio/cheatsheets/raw/master/data-transformation.pdf][data transformation with dplyr]]
In case it helps, here are some (sometimes outdated) French versions
of these documents:
- [[https://github.com/rstudio/cheatsheets/raw/master/translations/french/rstudio-IDE-cheatsheet.pdf][L'IDE Rstudio]]
- [[https://github.com/rstudio/cheatsheets/raw/master/translations/french/ggplot2-french-cheatsheet.pdf][Visualisation de données avec ggplot2]]
- [[https://github.com/rstudio/cheatsheets/raw/master/translations/french/data-wrangling-french.pdf][Transformation de données avec dplyr]]
- [[https://www.fun-mooc.fr/c4x/UPSUD/42001S02/asset/RMarkdown.pdf][Un court document sur R Markdown]]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment