How to import a .tsv file

Andrew Voronkov picture Andrew Voronkov · Oct 24, 2015 · Viewed 91.2k times · Source

I need to read a table that is a .tsv file in R.

enter image description here

test <- read.table(file='drug_info.tsv')
# Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
#   line 1 did not have 10 elements
test <- read.table(file='drug_info.tsv', )
# Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
#   line 1 did not have 10 elements
scan("drug_info.tsv")
# Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
#   scan() expected 'a real', got 'ChallengeName'
scan(file = "drug_info.tsv")
# Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
#   scan() expected 'a real', got 'ChallengeName'

How should I read it?

Answer

Robert picture Robert · Oct 24, 2015

This should do it:

read.table(file = 'drug_info.tsv', sep = '\t', header = TRUE)