Search code examples
htmlr

How to have jpeg images be read in from a folder and shown in rendered HTML file in R?


I am reading in files from a folder using the following method:

require(magick)
require(purrr)

folder <- list.files("location/to/folder_directory", pattern = ".jpeg", full.names = T)
image_plots <- map(folder, image_read)
print(image_plots)

When I do this, I see that the images are being read in from the folder into the R markdown. But when I knit, in my HTML file, all I see is that the images are present but not the actual image displayed. I want the actual plot to show and not the message that the plot was read in. How can I do that.


Solution

  • I figured out a solution that worked for me.

    require(knitr)
    
    folder <- list.files("location/to/folder_directory", pattern = ".jpeg", full.names = T)
    include_graphics(folder)