Trouble opening file in Rstudio - r

This is my code
dat <- read.csv("../rawdata/uscrime.csv")
and this is the error I am getting
Error in file(file, "rt") : cannot open the connection
why won't it open my file?
I have done this several times in other projects but now that I have started a new project I can't get it to work.

Related

RStudio cannot load web file, but R in terminal can; why?

I'm running RStudio on Ubuntu 18.04. When I want to load this data from GitHub
d <- read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/airline-safety/airline-safety.csv")
I get the following error message.
Error in file(file, "rt") : cannot open the connection to 'https://raw.githubusercontent.com/fivethirtyeight/data/master/airline-safety/airline-safety.csv'
In addition: Warning message:
In file(file, "rt") :
URL 'https://raw.githubusercontent.com/fivethirtyeight/data/master/airline-safety/airline-safety.csv': status was 'Problem with the SSL CA cert (path? access rights?)'
Yet when I run the very same command in the terminal it works without any error. How can that be? And how can I fix it?
That seems similar to issue 1079 which includes:
Please restart R
then install.packages(c("curl", "httr"))
then try again.
If this is not enough, follow swirldev/swirl/issue 475.

in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file: No such file or directory

I am trying to upload a file of csvs and other documents into R studio. My code looks like the following.
setwd("~/Dropbox/R")
getwd()
[1] "/Users/me/Dropbox/R"
myData <-read.csv("~/Dropbox/Exercise_Files")
The message returned is:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file '/Users/me/Dropbox/R/Exercise_Files': No such file or
directory
I can't understand why R is telling me no such directory when getwd() shows the directory I am using. Nor do I understand why I am being told that there are no such files--I put them into the directory! They are right there! Please help; I have tried everything.
You have to specify the .csv extension:
myData <-read.csv("~/Dropbox/Exercise_Files.csv")
list.files() worked for me. I discovered that all my text files were being seen in R as filename.txt.txt but were seen as filename.txt in the Windows file manager. I changed the files to filename (without '.txt') in Windows and now they read into R correctly.

R cannot open a connection

I am trying to use RTextTools for none .csv files.
data7 <- read_data('/Users/Ziegler1812/Desktop/Essays/Fall 2016/461/Data-PrelimforR/Data-PrelimforR4/', type = 'folder',index = '1.txt',1)
Error in file(file, "rt") : cannot open the connection In addition:
Warning message: In file(file, "rt") : cannot open file '1.txt': No
such file or directory
'1.txt' does in fact exist in that location, the problem is not the file's existence, it is getting to the location of the file.
The problem was that in RTextTools the index is not to be an index from within the folder, it is to either be the folder itself, or an outside entity that is similar to that within the folder. Further, the explanation shows that folder is for txt files, however 'delim' is for txt files, which is why I couldn't get it to work.
Thanks.

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
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
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.

R tool Reading a text file shows Error,

This is my question
if i input this to my R data Mining tool
mydata <- read.csv("filename.txt")
it will shows an error like below
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'filename.txt': No such file or directory
what can i do to clear this error
Use read.delim("Path of the file like C://Users//Desktop//filename.txt")
which has more options than read.csv

Resources