Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looping mutates #389

Open
KaiAragaki opened this issue Dec 12, 2023 · 1 comment
Open

Looping mutates #389

KaiAragaki opened this issue Dec 12, 2023 · 1 comment

Comments

@KaiAragaki
Copy link

It appears that when using for loops, magick acts much like the values are passed by reference rather than value (understandable, as these are externalptrs). However, I found this behavior a bit unexpected.

Toy example:

library(magick)

cutter <- function(imgs) {
  for (i in seq_along(imgs)) {
    img <- magick::image_crop(imgs[i], "100")
    imgs[i] <- img
  }
  imgs
}

image_info(logo)
#>   format width height colorspace matte filesize density
#> 1    GIF   640    480       sRGB FALSE    28576   72x72
image_info(cutter(logo))
#>   format width height colorspace matte filesize density
#> 1    GIF   100    480       sRGB FALSE        0   72x72
image_info(logo)
#>   format width height colorspace matte filesize density
#> 1    GIF   100    480       sRGB FALSE        0   72x72
@dcaud
Copy link

dcaud commented Dec 31, 2023

One part that is odd is that the final image_info doesn't do what I expect. But when reading the logo in from disk each call, it does do what I expect:

image_info(image_read("logo:"))
image_info(cutter(image_read("logo:")))
image_info(image_read("logo:"))

Your cutter function never modifies logo, so I continue to be stumped as to what is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants