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


#1

Hello,

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)
str(data1) 

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,


#2

Try:
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:


#3

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


#4

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)
str(data1)

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.


#5

I can not fix the solution :frowning:


#6

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


#7

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.