Getting started with tibbles
Creating tibbles
7. Read data from a file


In the real world, we rarely have data that's in memory or entered by hand. Usually, the data lives in a file. In our directory, we have a file in the .csv (comma-separated values) format. It's quite a common format.

Let's learn now how to read a .csv file to memory. We'll use the tidyverse function read_csv() to do this for our vegetable data, giving the file path as an argument. Since we don't need to change directories, we can just write "vegetables.csv" as the argument. Here's how it looks:


The nice thing about tibbles and tidyverse is that unlike base R functions, read_csv() does not automatically convert character (text) values to factors.

In R you can use / as a path separator regardless of the operating system you use.


Read data from a file named fruits.csv located in a folder named data. Use the read_csv() function and assign the result to the variable fruits.

Stuck? Here's a hint!


fruits <- read_csv("data/fruits.csv")