0

I'm trying to read a table into R in which the first column contains names that have a forward slash (e.g. D81P8DQ1_H0D06ADXX:2:2211:15347:81697#0/1), but whatever I do R doesn't let me upload the file. Does anyone have a suggestion on how to upload such a file without changing the names or ignoring the column containing the names?

Before/after example (as poster designated in the comment)

test <- read.table(file="~/test.txt", header=T, sep="\t", blank.lines.skip = FALSE, fill = TRUE)
head(test)
Read Chr 
1 D81P8DQ1_H0D06ADXX:2:2114:10169:64377 NA 
2 D81P8DQ1_H0D06ADXX:1:2109:13954:39195 NA 

test <- read.table(file="~/test.txt", header=T, sep="\t", comment.char="")
head(test)
Read Chr 
1 D81P8DQ1_H0D06ADXX:2:2114:10169:64377#0/2 4 
2 D81P8DQ1_H0D06ADXX:1:2109:13954:39195#0/2 15
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Jeannine
  • 1
  • 2
  • 1
    Probably `read.table` is reading the `#` symbol as a comment character. See http://stackoverflow.com/questions/7086945/how-can-read-numeral-signs-as-part-of-a-column-header/7086973#7086973 and [here](http://stackoverflow.com/questions/8568968/r-programming-read-csv-skips-lines-unexpectedly/8569286#8569286). – Blue Magister Mar 26 '14 at 22:15
  • If that's not the problem, you really should show us what your file looks like and give a minimal reproducible example. – Blue Magister Mar 26 '14 at 22:17
  • What do you mean by "doesn't let me upload the file"? Does it return an error? If so, what is the error? – jbaums Mar 26 '14 at 23:01
  • `write.table(data.frame(A=rep('D81P8DQ1_H0D06ADXX:2:2211:15347:81697#0/1', 5), B=runif(5)), {f <- tempfile()}, row.names=FALSE); read.table(f, comment.char='', header=TRUE)` works fine for me. – jbaums Mar 26 '14 at 23:03
  • Sorry for not being clear enough. As Blue Magister pointed out the problem was the "#" and adding comment.char="" to read.table solved the problem. Here's a before/after example: – Jeannine Mar 27 '14 at 01:13
  • > test <- read.table(file="~/test.txt",header=T, sep="\t", blank.lines.skip = FALSE, fill = TRUE) > head(test) Read Chr 1 D81P8DQ1_H0D06ADXX:2:2114:10169:64377 NA 2 D81P8DQ1_H0D06ADXX:1:2109:13954:39195 NA > > test <- read.table(file="~/test.txt",header=T, sep="\t", comment.char="") > head(test) Read Chr 1 D81P8DQ1_H0D06ADXX:2:2114:10169:64377#0/2 4 2 D81P8DQ1_H0D06ADXX:1:2109:13954:39195#0/2 15 – Jeannine Mar 27 '14 at 01:13

0 Answers0