[R] sink behavior

Daniel Gatti dmgatti at email.unc.edu
Tue Aug 7 02:03:22 CEST 2007


There is a package called 'safe' that produces an object which I can 
only write to a file using the sink() function.  It works fine if the 
sink() command is not inside of a function, but it does not write 
anything to the file if the command is within a function.

Sample code:
# Using a matrix because as a simple example.
dumpMatrix = function(mat) {
    sink(file = "mat.txt")
    mat
    sink(NULL)
}

# This will write the file correctly.
x = matrix(100, 10, 10)
sink(file = "x.txt")
x
sink(NULL)

# This will create an empty file.
dumpMatrix(x)

R 2.5.1
Windows XP, SP2

The sink() docs are full of warnings, but I'm not clear which one I've 
violated with this example.

Dan



More information about the R-help mailing list