I have a data file with the # sign as a delimiter that I would like to read using the read.file .
Primarily; it is a large data file, and I do not want to change the delimiter because:
- the risk of using another delimiter that already exists in the data (note: you can check, but point 2 makes it a little more complicated)
- I expect more of these data files with all
# characters as a separator, so I don't want to change the data files every time I would like to read these files again.
So, I assumed that I could use the sep argument of the read.file . But this did not work for the # sign, as I expected. Only the first column has been read. I tried different delimiters, everything worked fine except for the # sign. Below are some examples, including the # separator.
The file looks like this:
H1#H2#H3 a#b#c d#e#f
Code in R containing the results for the same file where I changed the delimiter. For = , | , @ and $ it works fine, but not for # ...
> read.table(file='test_data.dat', check.names=F, sep='=', header=T) H1 H2 H3 1 abc 2 def > read.table(file='test_data.dat', check.names=F, sep='|', header=T) H1 H2 H3 1 abc 2 def > read.table(file='test_data.dat', check.names=F, sep='@', header=T) H1 H2 H3 1 abc 2 def > read.table(file='test_data.dat', check.names=F, sep='$', header=T) H1 H2 H3 1 abc 2 def > read.table(file='test_data.dat', check.names=F, sep='#', header=T) H1 1 a 2 d
Can someone help me with this? Is this a known bug? Is there a workaround?
Thanks in advance for your help!