I have a data frame named raw
, with columns mostly of type character
, that I would like to inspect for data cleaning. I decided to send the unique values of each column as a list to a temporary text file, like this
if (interactive()) {
tmp <- tempfile(fileext = '.txt')
sink(file = tmp)
lapply(raw, unique)
sink()
file.show(tmp)
}
When I run this code en bloc, the text file is not written to (it comes up blank), but if I step through the lines I get my desired result.
I thought of introducing some kind of delay with Sys.sleep()
but that didn't work. I also read through the documentation of sink()
but couldn't find anything related to this behaviour.
I asked this question over at Stack Overflow and it was suggested that I use capture.output()
instead. This actually worked but I'm still curious to know why my initial code did not work.