Answer to your question
Yes, that's the meaning of the n argument in
xx <- readBin("toy_text.TXT", what = "raw",
n = 32*11*10)
The way I understand it, when you call readBin(), R will first ask the OS for memory of size n. Then it will start reading the content of the file and storing it in memory. If it finds an EOF (End of File signal) within the file, it stops reading; if it runs out of memory it stops reading.
So you need to guesstimate the size of the file before you start reading, overestimating the real size. That's what I did with n=32*11*10, because I knew the file should contain a 32 x 11 data frame, with typically less than 10 bytes per field.
Now if you really don't know anything about the file beforehand, you could try using file.size().
Recommended
Anyway, working with binary being a bit of a pain, I strongly recommend you stick with string functions. I still don't know why my previous writeLines() didn't work, but you can get it with:
xx <- readr::read_lines("toy_text.TXT",)
xx2 <- stringr::str_replace_all(xx, "\r", "\n")
readr::write_lines(xx2, "toy_text2.TXT")
And in that case:
$ hexdump -C toy_text.TXT | head
00000000 32 31 20 36 20 31 36 30 20 31 31 30 20 33 2e 39 |21 6 160 110 3.9|
00000010 20 32 2e 36 32 20 31 36 2e 34 36 20 30 20 31 20 | 2.62 16.46 0 1 |
00000020 34 20 34 0d 32 31 20 36 20 31 36 30 20 31 31 30 |4 4.21 6 160 110|
^
$ hexdump -C toy_text2.TXT | head
00000000 32 31 20 36 20 31 36 30 20 31 31 30 20 33 2e 39 |21 6 160 110 3.9|
00000010 20 32 2e 36 32 20 31 36 2e 34 36 20 30 20 31 20 | 2.62 16.46 0 1 |
00000020 34 20 34 0a 32 31 20 36 20 31 36 30 20 31 31 30 |4 4.21 6 160 110|
^