Is there a portable way to get the null device in R?
At the moment I am doing this:
dev.null <- ifelse(.Platform$OS.type == "windows", "NUL:", "/dev/null")
And later I can for instance sink(dev.null)
or try(..., outFile = dev.null)
.
However that doesn't seem very robust to me. Is there a better way to do it?
This thread is quite old, but was the first I found when googling this topic, so I thought it may be worth mentioning nullfile.
nullfile() returns a character string, which is "/dev/null" except on Windows where it is "nul:"
As of R version 3.6.0, this function is available in the base namespace. Otherwise, you can find it in the R.utils package
sink(nullfile())
print("I am about to be tossed into the void, irrespective of the OS this is run on")
sink()