load_file example

  1. Run usethis::use_test("load") and complete the new test-load.R.
test_that("load_file() handles all input types", {
  # Create sample data
  df <- tibble::tibble(x = 1, y = 2)
  path_csv <- tempfile()
  path_tsv <- tempfile()
  write.csv(df, path_csv, row.names = FALSE)
  write.table(df, path_tsv, sep = "\t", row.names = FALSE)
  
  # 1. Can it load a csv file ?
  expect_equal(load_file("test.csv", path_csv), df)
  # 2. Can it load a tsv file ?
  expect_equal(load_file("test.tsv", path_tsv), df)
  # 3. Does it give an error message for other types?
  expect_error(load_file("blah", path_csv), "Invalid file")
})