I am trying to run different versions of the same command in a for loop based on the value of i.
If i equals 1 or 6 run this: rasterImage(ringIMG2, -22, -22, 22, 22, interpolate=FALSE, angle =0)
If i equals 2, 3 or 5 run this: rasterImage(ringIMG2, -22, -22, 22, 22, interpolate=FALSE, angle =0)
If i equals 4 run this: rasterImage(ringIMG2, -23.5, -23.5, 23.5, 23.5, interpolate=FALSE, angle =0)
I am using a nested ifelse statement.
for (i in 1:6)
{
#adjusts size of image within the plot
ifelse(i %in% c(1,6), rasterImage(ringIMG2, -22, -22, 22, 22, interpolate=FALSE, angle =0),
ifelse(i %in% c(2,3,5), rasterImage(ringIMG2, -23, -23, 23, 23, interpolate=FALSE, angle =0),
rasterImage(ringIMG2, -23.5, -23.5, 23.5, 23.5, interpolate=FALSE, angle =0)
)
)
}
I keep getting the following error:
Error in ifelse(i %in% c(1, 6), rasterImage(ringIMG2, -22, -22, 22, 22, :
replacement has length zero
In addition: Warning messages:
1: In readPNG(paste0("R", i, ".png")) :
libpng warning: iCCP: known incorrect sRGB profile
2: In rep(yes, length.out = length(ans)) :
'x' is NULL so the result will be NULL
The code on its own is running fine:
rasterImage(ringIMG2, -22, -22, 22, 22, interpolate=FALSE, angle =0)
Well I'm still getting the first warning but that is not any real concern.
I have tried the simplifying and it seems to work...
check <- ifelse(i %in% c(1,6), print('Yes'))
[1] "Yes"
My syntax looks ok based on the link below:
ifelse(<condition>, <yes>,
ifelse(<condition>, <yes>, <no>)
)
)
Anyone got an idea where I'm going wrong?
Thanks!