Error in file(file, "rt") : cannot open the connection with R in Python

Dung Do Tien Aug 22 2021 691

I am a newbie to the R, and after researching my error as below extensively, I am still unable to find the fix for it. I have already checked my working directory and also made sure that the files are in the correct directory.

My app throw an Error in file(file, "rt") : cannot open the connection.

 Error in file(file, "rt") : cannot open the connection
file(file, "rt")

read.table(file = file, header = header, sep = sep, quote = quote,
    dec = dec, fill = fill, comment.char = comment.char, ...)

read.csv(file[i], header = T, sep = ",")
datamean3("file", "data", 1:10)
In addition: Warning message:
In file(file, "rt") :
  cannot open file './file.csv': No such file or directory

How can I fix it?

Thanks for any suggestions.

Have 2 answer(s) found.
  • B

    Blue Jame Aug 22 2021

    To fix this, you have to specify the working directory were out csv file is stored using the setwd function:

     setwd("D:/Projects/Python/ExamplePL/")      # Change working directory

    Now, we can execute exactly the same code as below:

     product_data <- read.csv("product_data.csv")    # Properly import data

    And it works for me.

  • T

    Trump McDonald Aug 22 2021

    Just change your directory <- ("./file") to directory <- ("./file/")

    so just don't make file folder you are working on.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close