file_string breaks I/O idempotency for empty files
MichaelChirico opened this issue · 0 comments
MichaelChirico commented
readLines
and writeLines
keep idempotency:
file.create(tmp <- tempfile())
readChar(tmp, file.size(tmp))
# [1] ""
l = readLines(tmp)
l
# character(0)
writeLines(l, tmp)
readChar(tmp, file.size(tmp))
# [1] ""
However this doesn't hold if we use file_string
:
file.create(tmp <- tempfile())
l = xfun::file_string(tmp)
xfun::write_utf8(l, tmp)
readChar(tmp, file.size(tmp))
# [1] "\n"
This is because file_string
uses paste(., collapse="\n")
which converts character()
to ""
:
paste(character(), collapse="\n")
# [1] ""