load_file example

You can also use the describe() and it() functions to create the test-load.R with better error descriptions.

describe("load_file()",{

  # Create sample data
  df <- tibble::tibble(x = 1, y = 2)

  it("can load a csv file",{
    path_csv <- tempfile()
    write.csv(df, path_csv, row.names = FALSE)
    expect_equal(load_file("test.csv", path_csv), df)
  })

  it("can load a tsv file",{
    path_tsv <- tempfile()
    write.table(df, path_tsv, sep = "\t", row.names = FALSE)
    expect_equal(load_file("test.tsv", path_tsv), df)
  })

  it("gives an error message for other types",{
    expect_error(load_file("blah", path_csv), "Invalid file")
  })

})
> devtools::test()
ℹ Testing quicktest
✔ | F W  S  OK | Context
✖ | 1        2 | load                                                                              
───────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-load.R:21:5): load_file(): gives an error message for other types