Skip to content

Commit

Permalink
Only display warning message if reading has failed
Browse files Browse the repository at this point in the history
See discussion #398
  • Loading branch information
jeroen committed Jul 20, 2024
1 parent 407dba3 commit 7e18daa
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions R/edit.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ image_read <- function(path, density = NULL, depth = NULL, strip = FALSE, coales
density <- as.character(density)
depth <- as.integer(depth)
defines <- validate_defines(defines)
if(is.character(path) && grepl("\\.pdf$", path) && Sys.which('gs') == "" && !file.exists('C:\\Program Files\\gs')){
message("Ghostscript (gs) not found on the PATH.\nTry image_read_pdf() to read PDF using pdftools instead.")
}
image <- if(isS4(path) && methods::is(path, "Image")){
convert_EBImage(path)
} else if(inherits(path, "nativeRaster") || (is.matrix(path) && is.integer(path))){
Expand All @@ -90,7 +87,12 @@ image_read <- function(path, density = NULL, depth = NULL, strip = FALSE, coales
} else {
enc2native(path)
}
magick_image_readpath(path, density, depth, strip, defines)
withCallingHandlers(magick_image_readpath(path, density, depth, strip, defines), error = function(err){
# Here we can put some additional diagnostics in case imagemagick fails
if(grepl("\\.pdf$", path) && Sys.which('gs') == ""){
message("Ghostscript (gs) not found on the PATH.\nUse: image_read_pdf() to read with pdftools.")
}
})
} else {
stop("path must be URL, filename or raw vector")
}
Expand Down

0 comments on commit 7e18daa

Please sign in to comment.