Installing R packages
After installing R and R-Studio, you still need to install a number of so called R packages. We will learn more about what packages are and how to use them later. Nevertheless, I strongly recommend you to install already all the packages you will need over the following semester already now. This way you make sure that everything is working now, and you save yourself from trouble during the semester. Moreover, installing these packages is necessary to do the exercises provided after each session.
To install packages, a stable internet connection is required. Then, proceed as follows:
- Download the script install_packages_script.R and save it in a directory of your choice
- Open the file
install_packages_script.R
in R-Studio. To this end, right-click on the file and selectOpen with
, and then choose R-Studio. - Adjust the first line of the script to the OS you are using. For instance, when you are using a Mac the file should look like this:
- Select lines 1-52 and click on the button
Run
(the screenshot only shows the lines 42-52, the previous lines are also selected):
- Check if the package
here
was installed. You will get the respective message in the console:
If you encounter any problems, please make a screenshot and post it in the Moodle forum.
- Select the rest of the scrip and run it as you did with the first lines. If you get the following message everything worked well and all packages were installed successfully:
If not, please post the file InstallationLog.txt
and a screenshot with an error into the Moodle forum.
Note: maybe you will see the following message during the installation process (possible multiple times):
I recommend to type No
and press enter. If, for any reason, the installation process is not successful you might run the installation commands again and try responding with Yes
, this might sometimes fix the problem.
Verify the usability of exercises
If everything worked well until here you should be able to access the exercise sheets that I provide you with after each session. To make sure everything works as expected, please run the following command in the console and press enter:
::run_tutorial(
learnrname = "Basics",
package = "DataScienceExercises",
shiny_args=list("launch.browser"=TRUE))
This means you type it like this and press enter:
If the exercise window opens, everything is well, if not, please describe your problem in the Moodle forum.
After you closed the window and the process is still active, just click on the Stop
button in R-Studio:
And then click on the Console
tab on the left to return to the console.
Installing LaTeX
To create PDF-documents you have to install a Latex distribution. I recommend you to install the distribution tinytex, no matter whether you already have a different distribution or not.
I recommend installing tinytex via Quarto. You should have installed Quarto during this tutorial, but in case you did not, just follow the instructions on this webpage.
Then follow the instructions from this tutorial. What you essentially need to do is to open your terminal and issue the following command:
quarto install tinytex
To make sure everything runs smoothly you should download the document test_pdf.qmd (its a zip file that you first need to extract).
To test whether everything works, please open test.qmd
in R-Studio and then click on the button Render
(which is a couple of buttons left of Run
).
If this works you are all set. If there are any errors showing up, please post a screenshot and a problem description to the Moodle forum.
A common problem when installing tinytex on a Mac
The following hints should be helpful if after the attempted installation of tinytex
you see either one of these error messages:
In this case, execute the following comment in your R console within R-Studio:
::install_tinytex(force = TRUE) tinytex
Then close R-Studio and restart your computer. If test_pdf.qmd
still cannot be compiled after this, please open your Mac Terminal (via the app Terminal
) and enter the following commands:
sudo chown -R `whoami`:admin /usr/local/bin
~/Library/TinyTeX/bin/x86_64-darwin/tlmgr path add
Then install tinytex
again as described above, restart your computer, and try to compile test_pdf.qmd
again.