I have the error
Error in writePNG(sample, target = outfile) : image must be a matrix or array of raw or real numbers
From the following instructions :
#any dataframe with dim nrows and 112*92 columns
#and coefficients between 0 and 1
dataf = data.frame(matrix(runif(112*92*3),nrow=3,ncol=112*92))
sample = dataf[1,]
sample = matrix(sample,112,92)
outfile <- tempfile(fileext = ".png")
writePNG(sample, target = outfile)
It seems that the process of converting a data frame to a matrix itself is the problem. Using str on a matrix and a data frame-originated matrix give a different output too.
Edit : As suggested as.matrix does the trick, but precising ncol and nrow doesnt give you the object of desired dimension quite weird. Hence I use : dim(dataf) = c(nrow,ncol)