I've created a package that has a function, in this case is myfunction(argument1, argument2), that requires only positive inputs that have the same length as arguments. And I want to test whether the input is in a correct format using functions from testthat package. The point here is that I want to test whether the inputs are qualified to be the arguments of the function or not?
I have something like:
test_that("myfunction works", {
input1 <- c(200, -220, 250)
input2 <- c(30, 40, 50)
myfunction(input1, input2)
expect_equal(length(input1), length(input2))
})
Now I want to test that all my arguments (input1, input2) contain only positive numbers. How could I do that? I actually tried this:
expect_true(input1[] > 0)
expect_true(input2[] >0)
and
expect_gt(input1[], 0)
expect_gt(input2[], 0)
but then receive an error message:
Error: Result of comparison must be a single logical value
It seems like the expect_...() family functions are only applied for single values rather than a vector or a data frame? Any suggestions on what I should try?