Closed hongooi73 closed 7 years ago
I just ran into this today. If I pass a file or pathname that contains a dot to save.image, and ImageMagick isn't available, the save fails:
save.image
> save.image(boats, file="my.file.jpg") Error in save.image(boats, file = "my.file.jpg") : Unsupported output file format. Use jpg/png or install ImageMagick > save.image(boats, file="temp.folder/myfile.jpg") Error in save.image(boats, file = "temp.folder/myfile.jpg") : Unsupported output file format. Use jpg/png or install ImageMagick
The underlying cause is the regex that save.image uses to detect the file type:
ftype <- stringr::str_match(file, "\\.(.+)$")[1, 2] if (ftype == "png") ...
If file contains more than one dot, it will match everything past the first dot:
file
> stringr::str_match("my.file.jpg", "\\.(.+)$") [,1] [,2] [1,] ".file.jpg" "file.jpg"
Replacing the regex with \\.([^.]+)$ should fix this:
\\.([^.]+)$
> stringr::str_match("my.file.jpg", "\\.([^.]+)$") [,1] [,2] [1,] ".jpg" "jpg"
Thanks a lot for the bug report! Fixed in current branch ("pixset").
I just ran into this today. If I pass a file or pathname that contains a dot to
save.image
, and ImageMagick isn't available, the save fails:The underlying cause is the regex that
save.image
uses to detect the file type:If
file
contains more than one dot, it will match everything past the first dot:Replacing the regex with
\\.([^.]+)$
should fix this: