I've been trying to develop an R code that allows to extract the different parts of an agarose gel corresponding to different samples. For this I've tried to dynamically export the differente cropped images using loop (for) function in this way:
for (i in 1:length(get("project"))) {
imagewrite(get( "gel",project[i] ), paste0("gel_", project[i] ,".jpg"),format = "jpg")
}
where variable:
project: contains the names of the projects. Ex.: UCE, ESPE, ST1
get("gel_",project[i]): calls for the cropped images. Ex.: variable named "gel_UCE" is an External pointer of class "magick-image"
paste0("gel_",project[i],".jpg"): generates the name of the cropped image for each project Ex.: for gel_UCE image creates names "gel_UCE.jpg"
Running this line independently works fine. However, I've been trying to create a function to run the code in one line. When I run the complete function (which includes the line I've shown), this error ocurrs.
It seems that the function "image_write" doesn't work when I try to dinamically export the images, by generating the variables with the get function. Is there a way to overcome this issue?
I've been trying to develop an R code that allows to extract the different parts of an agarose gel corresponding to different samples. For this I've tried to dynamically export the differente cropped images using loop (for) function in this way:
for (i in 1:length(get("project"))) { imagewrite(get( "gel",project[i] ), paste0("gel_", project[i] ,".jpg"),format = "jpg") } where variable:
Running this line independently works fine. However, I've been trying to create a function to run the code in one line. When I run the complete function (which includes the line I've shown), this error ocurrs.
It seems that the function "image_write" doesn't work when I try to dinamically export the images, by generating the variables with the get function. Is there a way to overcome this issue?