Library of alternativeFunction() in R - 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"

Related

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]])

Can't read CSV file with R script

I'm still very new to R and I'm trying to read a moderate-size .csv file with a Script, but the script is unable to detect the file.
My code is at follows:
Saint<- read.csv("./Comp1.csv", stringsAsFactors = FALSE)
Saint
I have attempted several ways to indicate the file path. Including
path<- file.path("desktop", "saint", "Comp1.csv"
Then using the path variable in the read.csv function.
Also explicitly indicating the full path with forward slashes
It always throws the following error
> Saint<- read.csv("./Comp1.csv", stringsAsFactors = FALSE)
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file './Comp1.csv': No such file or directory
>
> Saint
Error: object 'Saint' not found
Any ideas on what might be wrong here?

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.

Using R to Download and extract zip file that contains a folder

In Rstudio I wrote:
urlcoP <- "http://www.cophieu68.vn/datax123456/metastock_all_data.zip"
temp <- tempfile()
download.file(urlcoP,temp)
data <- read.table(unz(temp, "metastock_all_data.txt"))
But it's get the error:
Error in open.connection(file, "rt") : cannot open the connection
In addition: Warning message:
In open.connection(file, "rt") :
cannot locate file 'metastock_all_data.txt' in zip file 'C:\TEMP\RtmpaaH3PW\file135c1e97348'
The reason is that the metastock_all_data.txt is in a folder called datax123456 in the zip.
try this?
data <- read.table(unz(temp, "datax123456/metastock_all_data.txt"))
metastock_all_data.txt is in a folder called datax123456 in the zip, hence add the folder before metastock_all_data.txt

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