From 70d4e105bf68635d18a2d40b38092bf08aed31c5 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Fri, 31 May 2024 02:08:56 +0200 Subject: [PATCH] add support for .jpg format in `preview_plot()` --- R/preview-utils.R | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/R/preview-utils.R b/R/preview-utils.R index eac51640..10a6cab8 100644 --- a/R/preview-utils.R +++ b/R/preview-utils.R @@ -2,7 +2,7 @@ #' #' This is a helper function to plot preview assets #' (e.g. quicklook, thumbnail, rendered_preview). -#' Currently, only png and jpeg formats are supported. +#' Currently, only png, jpeg and jpg formats are supported. #' #' @param url image URL to be plotted. #' @@ -12,7 +12,7 @@ preview_plot <- function(url) { preview_check(url) img <- preview_read_file(url) - plot(1:10, ty = "n", axes = F, xlab = "", ylab = "") + plot(1:10, type = "n", axes = FALSE, xlab = "", ylab = "") grid::grid.raster(img) } @@ -39,6 +39,12 @@ preview_check <- function(url) { "This function requires `jpeg` package. Please, use", "install.packages('jpeg')." )) + , + jpg = if (!requireNamespace("jpeg", quietly = TRUE)) + .error(paste( + "This function requires `jpeg` package. Please, use", + "install.packages('jpeg')." + )) ) } @@ -55,7 +61,8 @@ preview_read_file <- function(url) { preview_switch( url, png = png::readPNG(temp_file), - jpeg = jpeg::readJPEG(temp_file) + jpeg = jpeg::readJPEG(temp_file), + jpg = jpeg::readJPEG(temp_file) ) }