#' arts_images
#' extract the primary picture of artworks matching parameters
#' Input the objectIDs from the previous function that you're interested
#' @param objectIDs eg. c(13875, 229930) for multiple IDs
#'
#' @return A table with the object ID, name, and photo
#'
#' @importFrom utils head write.csv
#' @export
arts_images <- function(objectIDs) {
## collect urls
urls <- stringr::str_c("https://collectionapi.metmuseum.org/public/collection/v1/objects/", objectIDs)
## collect raw observations
obs <- c()
for(url in urls){
request_result <- GET(url)
## check if there is a false ID that doesn't exist
if(httr::http_error(request_result)){
falseID <- stringr::str_sub(url, 66, )
warning("objectID ")
cat(falseID)
warning(" does not exist! Check your typo :D
")
} else {
cont <- httr::content(request_result)
obs[[length(obs)+1]] <- unlist(cont)
}
}
## collect focused observations
images <- c()
for (i in 1:length(obs)) {
df <- obs[[i]] %>%
t() %>%
as.data.frame()
images[[length(images)+1]] <- df[ , c("objectID",
"objectName",
"primaryImageSmall")]
}
## neat dataframe
table <- do.call(rbind, images)
## build links to images
table$primaryImageSmall <- stringr::str_c("")
## print
table %>% knitr::kable()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.