tests/testthat/test-download-file.R

test_that("download_file() works", {

  myurl <- "https://github.com/privefl.png"
  png <- download_file(myurl, quiet = TRUE)
  expect_identical(png, file.path(tempdir(), "privefl.png"))
  mtime <- file.info(png)[["mtime"]]

  expect_identical(download_file(myurl), png)
  expect_identical(file.info(png)[["mtime"]], mtime)  # file was not modified

  Sys.sleep(2)
  download_file(myurl, overwrite = TRUE, quiet = TRUE)
  expect_gt(file.info(png)[["mtime"]], mtime)  # file was modified
})

Try the runonce package in your browser

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

runonce documentation built on Oct. 2, 2021, 9:06 a.m.