Skip to content
Prev 30339 / 63424 Next

writting null (\000 or ^@) to an external text file without the new warning

2008/10/28 Greg Snow <Greg.Snow at imail.org>:
The warning happens when you construct the string, so somehow you
have to avoid making the string. How about using writeBin with a
connection opened in binary mode:

 > con=file("test2.raw","wb")
 > writeBin(as.raw(1),con,size=1)
 > writeBin(as.raw(0),con,size=1)
 > writeBin(as.raw(0),con,size=1)
 > writeBin(as.raw(7),con,size=1)
 > close(con)
 >
Save workspace image? [y/n/c]: n

 now lets dump it:

 rowlings at fab008000006:~$ od -x test2.raw
 0000000 0001 0700
 0000004

 Which I think is correct, maybe some fiddling with endianness is needed...

Barry