Error in file.choose() file choice cancelled

Thanks! Give this a try:

Replace this line:

data <- read.csv2(file.choose(), encoding="latin1")

with this one:

data <- read.csv2("name_of_your_file.csv", encoding="latin1")

That works because it’s a relative file path: since the CSV and the .Rmd are in the same folder, the path from the .Rmd to the CSV is just the name of the CSV file. It’s like telling the .Rmd, “look at the files sitting next to you and find the one called ‘name_of_your_file.csv’”.


By the way, do you know that RStudio can help you fill in file paths like this one? When you need to enter a file path, try just typing the quotes and then (with your cursor between the quotes) pressing tab — RStudio will pop up a little window that browses for nearby files and when you choose one, it inserts the correct path into your code.

We also have a great thread here with resources for people who are new to R and RStudio that you might want to check out:

2 Likes