Read and write JPEG images in R