Files: read & write

Read

# read tabulator separated text files (into R as "data-frame" table)

mydata = read.table('mydata_text_file.csv', header=TRUE, sep="\t", row.names=1 )

# or alternatively

mydata = read.csv('mydata_text_file.csv', header=TRUE, sep="\t", row.names=1 )

→ working with "data-frame" table

Write

# write data to text file

write.csv2(mydata, file='mydata.csv', quote = FALSE)

write.table(mydata, file = 'mydata.txt', append = FALSE, quote = FALSE, sep = "\t", eol = "\n", na = "missing", dec = ".", row.names = TRUE, col.names = NA, qmethod = "double")

# write strings to text file, line by line

mytext = c('A1','A2','A3')

fid <- file('output_file.txt')

writeLines( mytext , fid)

close(fid)

A1

A2

A3

read more

http://www.r-tutor.com/r-introduction/data-frame/data-import