tests/testthat/test_errors.R

context("Worst-case scenarios")

file <- system.file("extdata", "dt_iris.csv", package = "fplyr")


test_that("fplyr handles errors", {
    expect_error(
        ftply(file, FUN = function(d, by) {
            stop("Simulation of error")
            d
        })
    )
    expect_identical(
        ftply(file, FUN = function(d, by) {
            tryCatch({
                if (by == "versicolor")
                    stop("I hate versicolor")
                else
                    return(d)
            },
            error = function(e) {
                message(e$message)
                return(NULL)
            })
        }),
        fread(file)[Species != "versicolor", ]
    )
    expect_identical(
        ftply(file, FUN = function(d, by) {
            NULL
        }),
        data.table()
    )
})

Try the fplyr package in your browser

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

fplyr documentation built on Aug. 24, 2023, 1:08 a.m.