Download random HD images from various unsplash.com categories in R using the Quickcode package"

# install quickcode if not available
# install.packages(quickcode)

# load quickcode library
library(quickcode)
#clean() #clear the environment

# let's load the r2resize to provide toolbars for the image resizing
library(r2resize)
add.resizer(line.color = "brown", line.height = "3", default.image.width = "30%")

Download 3 random images from the school category and display

For this example, we will download 3 random png images from the web in the category of 'school' to a temp directory and then display it. The r2resize package provides the image resizer that lets us view the images nicely below.

storlocation <- tempdir()
genRandImg(fp = storlocation, n = 3, cat = "school", ext = "png")

getdownloadedfiles = list.files(path = storlocation, pattern = ".png", full.names = TRUE)

Display the images:

r paste0("![](",getdownloadedfiles[1],")") r paste0("![](",getdownloadedfiles[2],")") r paste0("![](",getdownloadedfiles[3],")")

Download 6 random images from the animals category and display

For this example, we will download 6 random jpg images from the web in the category of 'school' to a temp directory and then display it.

storlocation2 <- tempdir()
genRandImg(fp = storlocation2, n = 6, cat = "animals", ext = "jpg")

getdownloadedfiles = list.files(path = storlocation2, pattern = ".jpg", full.names = TRUE)

Display the images:

r paste0("![](",getdownloadedfiles[1],")") r paste0("![](",getdownloadedfiles[2],")") r paste0("![](",getdownloadedfiles[3],")") r paste0("![](",getdownloadedfiles[4],")") r paste0("![](",getdownloadedfiles[5],")") r paste0("![](",getdownloadedfiles[6],")")

Quick links



Try the quickcode package in your browser

Any scripts or data that you put into this service are public.

quickcode documentation built on April 11, 2025, 5:49 p.m.