#' Download kitten from the internet.
#'
#' We use the \code{mode="wb"} download mode to donwload files reliably on windows.
#'
#' The default is to download to a temporary file. Do not specify a directory name for
#' \code{destfile} or you will get a cryptic error message!
#' @title Download kitten
#' @param width Width, in pixels, of the kitten to download
#' @param height Height, in pixels,
#' @param ... Additional arguments to \code{\link{download.file}}
#' @param destfile Place to put the file. By default a temporary file will be created with a ".jpg" extension
#' @return The name of the destination file, which may be useful if
#' using the default (which is a temporary file)
#' @author Rich FitzJohn
#' @export
#' @examples
#' dest <- kitten(300, 200)
#' browseURL(dest)
kitten <- function(width, height, ..., destfile=tempfile(fileext = ".jpg")) {
if (width <= 0 || height <= 0) {
stop("Must have positive sizes for width and height")
}
url <- sprintf("http://placekitten.com/g/%d/%d", width, height)
download_file_portable(url, destfile, ...)
destfile
}
download_file_portable <- function(url, destfile, ...) {
utils::download.file(url, destfile, ..., mode="wb")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.