For the lab sessions, we will be utilizing a system called "Jupyter notebooks". The huge advantage for you (and us) is that we do not have to bother with setting up R and and an editor for R on your local computer. The disadvantage is that these notebooks "live" on a server and can only be accessed when you are online. However, you can alwys save these notebooks to your computer (in different file formats if you like).
As a side note for those who know Python: Jupyter notebooks can, of course, also installed locally, for more information, see http://jupyter.org/install.
Notebooks are interactive documents composed of "cells". These "cells" can contain text as well as code, e.g. R or Python code. Most paragraphs in this section are cells (of type Markdown, which is a simple markup language, see section Markdown for more information). The next paragraph/cells, however, is a code cell, showing the full power of R:
4*2+1-1/1
We also can include plots very easily:
options(repr.plot.width = 4, repr.plot.height = 3) ## this line changes the plot size
hist(rnorm(100))
Jupter notebooks (short: notebooks) are interactive documents, where R code and documentation (Markdown formated text) can be combined.
Notebooks are composed of cells, e.g., this paragraph is a single Markdown/text cell. Cells can also be of type "Code" (here: R code). Code cells can be executed, that is, the R code in this cells is executed.
If you activate a cell, either by clicking in it or by by moving your cursor through the document (and then hitting "Return"), you can manipulate existing cells.
https://notebooks.gesis.org/binder/jupyter/user/berndweiss-gesi-a-analysis-2018-o23m58a1/tree?token=h8g583spRoe_Qlz2bEhvfw
. Again, this only works for about 30 minutes after closing the notebook. if you want permantely save the notebook, see the next bullet point.Cells can be updated, executed (run), deleted, and added. You can this either by using the menu above (see "Insert", "Cell" or "Edit"). To speed things up, though, it is always a good idea to learn a few shortcuts (see the section on "Shortcuts"). Before going into detail, we have to introduce the two modes a cell can have: edit mode and command mode.
To execute a cell, choose "Cell" in the menue and then "Run cells" or one of the other commands. If you execute a Markdown cell, it will render the text. And, if you execute an R code cell, the R code will be executed. Code cells also have a little "play button >|" on the left side of the cell. Check out the R code cell below.
1+1
To execute all cells of a notebook, go to "Cell" and select "Run all".
You can save (and download) the Jupyter notebook as well as export it to various formats (HTML, PDF etc.).
solved Notebooks can have table of contents, which can make navigation much easier. Unfortunately, you have to turn on this feature each time you start your notebooks.To do so, go to the Nbextensions
tab.
Next, activate the Table of contents (2)
checkbox, see screenshot below. That should do it.
Brief reminder about "modes": You can either be in "command" or in "edit" mode when working with Jupyter notebooks. When you want to edit a cell, you can switch to "edit mode" by clicking into the respective cell or be hitting the "Return" key. You can go back to "command mode" by hitting the "Esc" key.
When in command or edit mode:
When in command mode:
Markdown is a simple markup language (or "a plain text formatting syntax"). That is, you write *awesome*
to emphasize the word awesome or **bold**
for bold. The original Markdown website is https://daringfireball.net/projects/markdown/.
In the context of Jupyter notebooks, however, we recommend the following websites: