Skip to content

Instantly share code, notes, and snippets.

@richfitz
Last active November 11, 2016 16:17
Show Gist options
  • Save richfitz/a1e0303547441fefbb98292582f81336 to your computer and use it in GitHub Desktop.
Save richfitz/a1e0303547441fefbb98292582f81336 to your computer and use it in GitHub Desktop.
#' Download kittens from the internet
#'
#' This is the details section
#'
#' @title Download kittens
#' @param width Width of the kitten, in pixels
#' @param height Height of the kitten, in pixels
#' @param destfile Place to download the kitten to. \code{\link{tempfile}()} makes a good place
#' @param ... Additional arguments passed through to \code{\link{download.file}}
#'
#' @return Returns the filename of the kitten (i.e., \code{destfile})
#' @export
#'
#' @examples
#' # download a small cat
#' file <- kitten(100, 100, tempfile())
#' # download a very large cat
#' file <- kitten(1000, 100, tempfile())
kitten <- function(width, height, destfile, ...) {
url <- make_url(width, height)
fetch_file(url, destfile)
destfile
}
make_url <- function(width, height) {
sprintf("http://placekitten.com/g/%d/%d", width, height)
}
fetch_file <- function(url, destfile, ...) {
download.file(url, destfile, ..., mode = "wb")
}
another_function <- function() {
message("I am a hidden function")
}
context("kitten")
test_that("downloads work", {
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment