Akinosun Opemipo
Akinosun Opemipo

Reputation: 1

Importing a CSV file into R

I am Using a MACbook and new to R. I have the social network file on my desktop and I'm trying to get R to read it. I saved it as CSV

command typed:

sn.csv <- read.csv("C:\Users\Opemipo Akinosun\Desktop\social_network.csv", header = T)

I keep getting the following errors:

error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'C:/Users/Opemipo Akinosun/Desktop/social_network.csv': No such file or directory

the resource I'm learning with doesn't ask me to set my directory so I'm a little reluctant to doing that as suggested

Upvotes: 0

Views: 562

Answers (2)

Learner
Learner

Reputation: 1

I worked and I could resolve the issue I was facing. Try changing the directory and then use the above code. So it will be as below

setwd("C:/Users/user/Desktop")
sn <- read.csv("social_network.csv" , header = TRUE)
sn

Run the above command and you should be all set to work further.

Upvotes: 0

agstudy
agstudy

Reputation: 121608

You should use file.path that is OS-independant :

ff <- file.path("C:","Users","Opemipo Akinosun","Desktop","social_network.csv")

Then you can check if the file exists:

> file.exists(ff)
[1] FALSE

Upvotes: 3

Related Questions