Portable null device in R

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?

6

1 Answer

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()

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like