tests/testthat/code.R

## A test.  There are two ways this could go:
##
## 1. Encode the filename yourself:
## download_data <- function() {
##   write.csv(mtcars, "data.csv")
## }
## 2. Encode the filename in the argument:
download_data <- function(dest) {
  f <- file(dest, "wb")
  on.exit(close(f))
  write.csv(mtcars, f)
}

process_data <- function(filename) {
  x <- read.csv(filename)
  x$kmpl <- x$mpg * 1.6 / 3.9
  x
}

do_plot <- function(dat, filename) {
  pdf(filename)
  on.exit(dev.off())
  myplot(dat)
}

myplot <- function(dat) {
  ## add a title:
  plot(kmpl ~ disp,   dat, main="myplot")
}

clean_hook <- function() {
  message("running post-cleanup hook")
}

generate_function <- function() {
  function(a, b = "wow") NULL
}
richfitz/remake documentation built on May 27, 2019, 8:27 a.m.