6.3 Summary

ds4psy: (6) Importing data

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 et al., 2018) that allow reading and writing data from a variety of files and formats.

After working through this chapter, you are able to:

  1. orient yourself on your computer (i.e., know your working directory and specify absolute and relative paths to other directories);
  2. use readr commands to
    • parse vectors of various data types;
    • import files of various formats;
    • export files in various formats;
  3. 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, 2019) is the tidyverse instrument to start playing with strings.28 Pointers to resources for importing additional data formats are provided in Sections 6.2.4 and 6.5. Finally, see the R Studio Cheat Sheet 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:

The [R Studio Cheat Sheet](https://www.rstudio.com/resources/cheatsheets/) on importing and exporting data with the **readr** package.

Figure 6.2: The R Studio Cheat Sheet on importing and exporting data with the readr package.

Let’s test our knowledge about data import and parsing skills by completing the following exercises.

References

Wickham, H. (2019). stringr: Simple, consistent wrappers for common string operations. Retrieved from https://CRAN.R-project.org/package=stringr

Wickham, H., Hester, J., & Francois, R. (2018). readr: Read rectangular text data. Retrieved from https://CRAN.R-project.org/package=readr


  1. See the Chapter 14 on Strings of r4ds (Wickham & Grolemund, 2017) for an introduction into parsing strings of text.