I am trying to read a zipped file into R from my working directory (D:/mywork
) using read.table function in R as shown below:
setwd("D:/mywork") # setting directory to read data from it
Data = read.table(gzfile("mywork/abc.txt.gz"),sep="\t")
Note: I set my directory using setwd("D:/mywork)
to read this file from it.
But it gave the following error for reading this file
When I tried to write the path of this file in read.table function
Data = read.table(gzfile("D:/mywork/abc.txt.gz"),sep="\t")
it worked. So is there any help to let the function reads this file directly from the working directory instead of writing the path every time for each dataset.
By the way,
read.table
can read gzip'd files straightaway, likeData<- read.table('abc.txt.gz')
, no need ofgzfile()
.