6.3 Summary
Importing data is a mundane step that we normally take for granted. However, as it is a prerequisite for anything that follows, it is important to get this step right. This chapter discussed essential commands of the readr package (Wickham, Hester, & Bryan, 2022) that allow reading and writing data from a variety of files and formats.
After working through this chapter, you are able to:
- orient yourself on your computer (i.e., know your working directory and specify absolute and relative paths to other directories);
- use readr commands to
- parse vectors of various data types;
- import files of various formats;
- export files in various formats;
- parse vectors of various data types;
- avoid exotic or proprietary file formats (not only in R).
Although mastering the steps and commands of this chapter will cover the most typical cases, keep in mind that there are many other forms and types of data. Perhaps the most common type of data to which we are exposed on a daily basis is text, but this usually does not come neatly packaged into rectangular form. The stringr package (Wickham, 2019b) is the tidyverse instrument to start playing with strings.46 Pointers to resources for importing additional data formats are provided in Sections 6.2.4 and 6.5. Finally, see the RStudio cheatsheet on importing and exporting data to check which readr commands you are now familiar with and which others you can still discover in the future:
Let’s test our knowledge about data import and parsing skills by completing the following exercises.
References
See the Chapter 14 on Strings of r4ds (Wickham & Grolemund, 2017) for an introduction into parsing strings of text.↩︎