I am stuck, reading data. Error in file(file, "rt")


I have problems with this code. The problem is that the directory is good:

 setwd("~/Desktop/Big Data and Marketing Intelligence/Semana 1/src")
data1 = read.csv("src/dat/transacciones.csv", header = TRUE, sep = ";", dec = ",", stringsAsFactors = FALSE)

This is the answer of R Studio:

Error in file(file, "rt") : no se puede abrir la conexión

I wish you can help me,

data1 = read.csv(“dat/transacciones.csv”, header = TRUE, sep = “;”, dec = “,”, stringsAsFactors = FALSE)

Your setwd statement already puts you in the src directory.

It is really recommended not to use setwd though:

1 Like

Also I did Session-Set Working Directory-Choose Directory. I tried with your code and does not run.

Another approach might be to make the path to the file an object and then call the object. I find this approach handy as most of my errors seem to be typos or issues with the file path.

data1 <- "~/Desktop/Big Data and Marketing Intelligence/Semana 1/src/dat/transacciones.csv"
read.csv(data1, header = TRUE, sep = “;”,  dec = “,”,  stringsAsFactors = FALSE)

You could also try out the readr package, which has the read_csv function to read in CSV files without the need to include stringsAsFactors = FALSE, and with some other nice data scrutiny bells and whistles.

I can not fix the solution :frowning:

Try navigating to the file using the tab key, i.e.
read.csv("~/Desktop/") etc.

1 Like

Sorry @IgorAzkune, it is never fun when you cannot get your data into R. I have made an attempt to replicate your example on my Mac with no issues, so I am not sure why you are getting the error. If it were me, I would try and debug by simplifying the path (e.g.move the file at least temporarily) and/or seeing if you can access a different CSV from the same location and so on.