R tool Reading a text file shows Error, - r

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

Related

Library of alternativeFunction() in R

I am trying to read 2 different types of files, using the alternativeFunction(). So if the first file in .txt format could not be found, I could try with the second type in .csv format, but R tells me that the function is not found. Does anyone know the library I have to install?
File <- try(read.table('File.txt',sep=c(',','|'), header=TRUE))
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'File.txt': No such file or directory
if("try-error" %in% class(File)) alternativeFunction(File <- read_csv('File.csv'))
Error in alternativeFunction(File <- read_csv("File.csv")) :
could not find function "alternativeFunction"

I cant speciy the file.path in R

Everytime I give the command in file.path, it always gives this error message , no matter what.
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'C/Users/Jbhanda/Desktop/NEW_GSE52778_All_Sample_FPKM_Matrix.csv': No such file or directory
I need to link my .csv file in desktop to the file.path command in R
First I note you are missing a colon after C, which (assuming this is a Windows machine) should be C:/.
Secondly you can try escaped backslashes:
C:\\Users\\Jbhanda\\Desktop\\NEW_GSE52778_All_Sample_FPKM_Matrix.csv

read.delim no such file or directory in R

I got a list of files from list.files() in current directory such that:
setwd("~/Data/LUSC/unc.edu_LUSC.IlluminaHiSeq_RNASeq.Level_3.1.2.0")
exprs_files <- list.files()
exprs_files <- exprs_files[grepl('gene.quantification', exprs_files)]
exprs_files[88]
[1] "UNCID_586826.TCGA-60-2720-01A-01R-0851-07.110426_UNC12-SN629_0078_BB08WCABXX.6.trimmed.annotated.gene.quantification.txt"
But I got error when read it:
read.delim(exprs_files[88])
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'UNCID_586826.TCGA-60-2720-01A-01R-0851-07.110426_UNC12-SN629_0078_BB08WCABXX.6.trimmed.annotated.gene.quantification.txt': No such file or directory
I am using RStudio Version 1.3.959 on Windows 10.
Any suggestions?
Try using a double bracket:
read.delim(exprs_files[[88]])

Why read.delim() cannot open text files?

I have saved an Excel file as Tab delimited, but when I try to open it I get the following error:
a=read.delim("GBM tab")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file 'GBM tab': No such file or directory
While I have a text file named GBM tab in my working directory.
Even when I press Tab, no matches are found. What is the problem?
One easier option is to use file.choose() and then just direct to the file in the directory
a <- read.delim(file.choose())
In the OP's code, it is possible that a file have .txt or .csv at the end it needs to be specified
a <- read.delim("GBM tab.txt")

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.

Resources