🗓️ Session 5a: Recap session
This on-site session was a pure recap session: no new material was introduced. Instead, we discussed the topics from the previous sessions that you wanted to go through again. We focused on two of them: how to tell R where your files are (absolute vs. relative paths and the here package), and the different object types in R and how they relate to each other.
The new material of this week, Quarto and R Markdown, is covered in the videos of session 5.
📂 Absolute and relative paths, and the here package
We discussed the difference between absolute paths (starting at the root of one specific computer) and relative paths (starting at the current working directory), and why only paths built with the here package keep working when your code moves to another computer, another folder, or another working directory.
We went through parts of a small hands-on exercise. The repository contains three scripts that read the same data file with an absolute path, a hard-coded relative path, and here, respectively. Download it as a ZIP file and work through the experiments described in its README:
The background is covered in Part III of the slides on project management from session 3, and in the following reading:
- Setting Up an R Project on Method and Inquiry (Gräbner-Radkowitsch 2026d)
🧱 Object types and their hierarchy
We then discussed the most important object types in R and how they build on each other. Here is the script we used in the session, but very much expanded to give you more details and examples:
The table summarises section 8 of ObjectHierarchy.R. Read it row by row: to transform an object of the type in the first column into the type in the header, use the function in the cell.
| from ↓ \ to → | logical | integer | double | character | list | factor | data.frame |
|---|---|---|---|---|---|---|---|
| logical | — | as.integer() |
as.double() |
as.character() |
as.list() |
factor() |
— |
| integer | as.logical() |
— | as.double() |
as.character() |
as.list() |
factor() |
— |
| double | as.logical() |
as.integer() |
— | as.character() |
as.list() |
factor() |
— |
| character | as.logical() |
as.integer() |
as.double() |
— | as.list() |
factor() |
— |
| list | unlist() |
unlist() |
unlist() |
unlist() |
— | — | as.data.frame() |
| factor | — | as.integer()* |
— | as.character() |
as.list() |
— | — |
| data.frame | — | — | — | — | as.list() |
— | — |
- Upwards in the atomic hierarchy (logical → integer → double → character) nothing gets lost.
- Downwards, values can be truncated (
as.integer(2.99)is2) or becomeNA(as.numeric("two")). - Always check the result with
typeof()orclass()after transforming an object.
The checklist at the end of ObjectTypesInPractice.R; go through it every time you work with a new data set.
The slides, videos and exercises are on the page of session 4. The relevant readings are:
- Object Types in R I: Functions on Method and Inquiry (Gräbner-Radkowitsch 2026a)
- Object Types in R II: Vectors on Method and Inquiry (Gräbner-Radkowitsch 2026b)
- Object Types in R III: Factors and Data Frames on Method and Inquiry (Gräbner-Radkowitsch 2026c)
✍️ Coursework
- Finish the experiments in the
here-paths-demorepository - If you have not done so yet, do the
ObjectTypes1andObjectTypes2exercises of the packageDataScienceExercises(see session 4) - If you have questions or problems, please post them in the Moodle forum