# read a sample file (R logo)
img <- readPNG(system.file("img","Rlogo.png",package="png"))
# write the image into a raw vector
r <- writePNG(img, raw())
# read it back again
img2 <- readPNG(r)
# it better be the same
identical(img, img2)
Run the code above in your browser using DataLab