1

I want to test my function that returns data.table, but there are problems. If the function returns data.table, then I should compare the resulting data. table with what I created manually? Maybe there is some function that would compare the resulting data. table with what I created?

I used this technique:

z <- read.csv("C:/Users/dima-/Dropbox/table.csv",sep=";")
library(testthat) 
test_that("data.table number", {
  expect_that(dt,equals(data))
})

I have an example function that returns data.table and I want to compare it with my data. table, I'm trying to figure out how best to test the function

z = data.table()
db <- iris
data <- function(dt){
  dt <- paste0(dt,"1")
  return(dt)
}

z <- data.table(data(db))
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick May 07 '21 at 06:43
  • 3
    To give you some example, have a look at the tests of the RITCH package [here](https://github.com/DavZim/RITCH/blob/master/inst/tinytest/test_read_functions.R#L26) (uses tinytest instead of testthat, but the tests look the same). – David May 07 '21 at 07:06
  • 1
    Maybe you want `expect_true(all.equal(dt, data))`? It's a bit unclear because the variable names don't seem to match up here and the example given doesn't seem to be identical so it should fail. – MrFlick May 07 '21 at 07:16
  • @David yes, I am currently studying this package – Дмитрий Юзов May 07 '21 at 07:26
  • @MrFlick this method suited me thank you – Дмитрий Юзов May 07 '21 at 07:27

0 Answers0