Import Data
This lesson is called Import Data, part of the Getting Started With R course. This lesson is called Import Data, part of the Getting Started With R course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Loading transcript...
View code shown in video
library(tidyverse)
read_csv("coffee_ratings.csv")
Your Turn
1. Create a new R script file and save it as import.R
2. Add the line library(tidyverse) at the top of your R script file and run it to load the tidyverse
3. Use the read_csv() function (not read.csv()) to import the coffee_ratings.csv file
Learn More
The coffee ratings data comes from the Tidy Tuesday project, a social coding project that releases new data each week and encourages people to analyze it, visualize it, and share their results on social media.
You need to be signed-in to comment on this post. Login.
Chris Mouzong • March 16, 2026
I'm getting this error message and can't import the coffee data (I can see the coffee ratings csv file on the explorer sidebar tab, so it seems to be there) : Error: ! 'coffee_ratings.csv' does not exist in current working directory ('c:/Users/cmouzong/Downloads/getting-started-positron-main'). Show Traceback
Gracielle Higino Coach • March 16, 2026
Hi Chris! Can you share the exact code you used? One tip that can help as a workaround is that you can grab the relative path of a file by right-clicking on it. Then you can paste this relative path to your
read_csv()function. This is especially helpful if you're not sure where your file is in relation to your project directory.Chris Mouzong • March 16, 2026
I used
read_csv("coffee_ratings.csv")Here's what the traceback message does:
Gracielle Higino Coach • March 16, 2026
Perfect, thank you! The fact that you see the file in the explorer menu does not necessarily mean that it is in the correct folder. The
coffee_ratings.csvfile should be in the same folder as theimport.Rfile (ideally it should be in a data-dedicated folder, but I get it!).The relative path solution through right-clicking the file should solve this, but ideally you should put the script and the data in the same folder.
Let me know if you have both in the same folder and still can't load the data!
Chris Mouzong • March 16, 2026
okay! Thank you! That was a good workaround to learn -- it worked, but when I copied the relative path and pasted, I got another error and had to go back in and change all of the backslashes in the path to forward/, and then it worked.
Gracielle Higino Coach • March 16, 2026
Awesome! Yeah, that's an annoying thing about R: paths in Windows work differently than in Mac and Ubuntu, but the R language uses only
\\or/. I didn't know that Positron didn't recognize the OS and produced the correct path, that's good to know!Feiran Chen • March 17, 2026
First question: I started this video after I closed and reopened Positron, so there is no folder open. There is a message on the left reminding me that no folder is open and asking me to open a folder. Is opening a folder always the first step?
Second question: what does the Import.R file do? Do I need to create a new Import.R file every time before I import data?
Thanks!
Gracielle Higino Coach • March 18, 2026
Hi Feiran! Yes, opening or creating a folder is always the first step so you know you're working on a designated project. You can, however, start by creating a new file, work on it, and only later save it to the corresponding folder, but then you'll probably have more work to use other files (like when importing data).
Regarding your second question, the Import.R script in this case is the one that you're using to practice importing a dataset to use in your workflow. You don't always need a script for importing data, nor they need to be called Import.R all the time. It is useful to have a separate script for that when the process of importing data gets complex, like when you have multiple sources or need to iterate to scrape data from a webpage. For any script, you just need to create them once. If you have your Import.R script ready, you can turn off your computer and return to work on the next day and just run the script - no need to re-create it!