# -*- mode: org -*-
#+TITLE: Rstudio
#+AUTHOR: Arnaud Legrand
#+DATE: June, 2018
#+STARTUP: overview indent
#+OPTIONS: num:nil toc:t
If you have never used git with Rstudio, *we strongly advise that you
follow the [[https://swcarpentry.github.io/git-novice/14-supplemental-rstudio/index.html][step-by-step explanations from Software Carpentry]]*. It comes
with many screenshots and is quite progressive. Alternatively, you
may want to watch this video:
#+BEGIN_EXPORT html
#+END_EXPORT
The next sections provide information on how to install Rstudio, Git
(to interact with GitLab), and SSH (to avoid typing your password
every time you synchronize with GitLab).
Finally, you need to know that the Rstudio team has created a lot of
very 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]]
* 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., 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., 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]]
- [[https://desktop.github.com/][GitHub Desktop]]
#+BEGIN_QUOTE
[[https://github.com/desktop/desktop/issues/852][Apparently]], this works with GitLab and https.
#+END_QUOTE
* Setting up SSH
There are two ways of synchronizing your local repository with GitLab:
through HTTPS or through SSH. The first one does not require any
particular configuration but you will be regularly prompted for your
GitLab password, which can be quite tedious. To avoid this, the best
solution is to set install SSH, to create a pair or private/public
keys, and to upload your SSH public key on GitLab. This section
provides with information on how to do this.
** Installation
*** 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., redhat, fedora).
Run (as root):
#+begin_src sh :results output :exports both
apt-get update ; apt-get install openssh-client
#+end_src
*** Mac OSX
You do not have anything to do as it is installed by default.
*** Windows
You should install the [[https://www.ssh.com/ssh/putty/windows/][Putty]] client. Once it is installed, look for
the section on [[https://www.ssh.com/ssh/putty/windows/puttygen][generating an SSH key]].
** Setting up SSH on Framagit
Here are [[https://docs.gitlab.com/ee/ssh/][all the official explanations on how to set up your SSH key
on GitLab]]. Alternatively, you may also want to have a look at this
video:
#+BEGIN_EXPORT html
#+END_EXPORT