R How to Solve Error in File RT – Cannot Open the Connection (2 Examples)

In this tutorial you’ll learn how to handle the error message “Error in file(file, “rt”) : cannot open the connection” in the R programming language.

Example 1: Why the Error Occurrrs

df <- read.csv2("data_file.csv")                   # Import of data doesn't work
# Error in file(file, "rt") : cannot open the connection
# In addition: Warning message:
# In file(file, "rt") :
#   cannot open file 'data_file.csv': No such file or directory

Example 2: How to Fix the Error Message

setwd("C:/Users/Data Hacks/Desktop/My Folder/")    # Switching working directory
df <- read.csv2("data_file.csv")                   # Importing data to R

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed