I have hundreds of images that I need to reformat using the magick package. I've written a function that uses parLapply from the parallel package to modify the images and store them in a list. However, when I try to view any of the images in the resulting list, I get: Error: Image pointer is dead. You cannot save or cache image objects between R sessions. When I use the same function with a regular lapply statement, the function works as intended, so I know it has something to do with my attempt to process in parallel.
Here is a small reprex. Thanks in advance for any help.
# Load images. img_url <- c("https://images.freeimages.com/images/large-previews/ce3/puppies-1-1308839.jpg", "https://images.freeimages.com/images/large-previews/006/young-dachshund-1362378.jpg") img_fun <- function (img) { # Set up parallel environment. require(parallel) cl <- makeCluster(2) clusterEvalQ(cl, { library(tidyverse) library(magick) }) # Process images. parLapply(cl, img, function (i) { image_read(i) %>% image_rotate(90) }) }