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.
Related
I tried to write my first function and use multiple files, I tried to create a directory
Step1. I create directory: "specdata", I run: getwd()
and get "/Users/wulingqi/Documents/R/coursera"
Step2. I unzip a zip file and move 332 csv files inside to the "specdata" folder
Step3. I run read.csv("1.csv") but get the error:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file '1.csv': No such file or directory
Step4. I searched on stack, and found this error may because of /spectdata/1.csv, which should be /spectdata1.csv
So I tried read.csv("1.csv",sep = "/") but get the same error.
Could someone give me some advice about this error? Thank you
f you changed your wd to ~/Documents/R/coursera/specdata, read.csv("1.csv") should do the job. From Martin Gal
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")
I just downloaded R onto my computer, but when I try to read a .csv file I get the following error:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file '[filename].csv': No such file or directory
This happens both when I command the program to read the .csv or when I try to import it manually (although that error code is slightly different).
Could this be because I don't have Microsoft Office (and subsequently, Excel) on my computer? The .csv file exists and is not corrupt because I have no problem uploading the file to Google sheets and displaying the data there. Either that, or I didn't install R correctly. Any suggestions?
No, you don't need any special packages to read plain text CSV files in R.
Looking at your error message:
Warning message: In file(file, "rt") : cannot open file '[filename].csv': No such file or directory
I would guess that the problem is your path to the file in question. As a quick fix, you can try using the fully qualified path to your file. For example, on Windows you might try this:
data <- read.csv(file="c:/path/to/filename.csv", header=TRUE, sep=",")
If this works, then the issue was the location of your CSV file. Then, if you want to continue using a relative path, you'll have to figure out what that would be given your current R setup.
I'm using Rstudio and I cannot open several file .txt because of this error message :
Error in file(file, "rt") : cannot open the connection
I enter :
X1= read.table("fileX1.txt", header = FALSE)
I don't understand because some of my colleagues use the same function with the same .txt file and it works for them
Since you aren't specifying the path to the file, R will look for it in the current directory. If that isn't the directory containing the file, you'll get that error.
You can use setwd() (or a menu command in RStudio) to set the current directory. Alternatively, you could use file.choose() to get a dialog to choose the file; it will return the full filename including the path.
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.