library(testthat) library(data.table) library(DTwrappers2) # Convert iris to a data.table once before the tests begin data("iris") setDT(iris) # Convert to data.table describe("dt.mean.numerics functionality", { it("computes mean values correctly with filter and grouping", { mean_values <- dt.mean.numerics( dt.name = "iris", the.filter = "Sepal.Length > 4 & Sepal.Length < 6", grouping.variables = "Species" ) # Convert the expected Species column to a factor to match the actual results expected_means <- data.table( Species = factor(c("setosa", "versicolor", "virginica")), Sepal.Length = c(5.006000, 5.53076923 , 5.64285714), Sepal.Width = c(3.428000, 2.67307692, 2.71428571), Petal.Length = c(1.462000, 3.9692308 , 4.9714286), Petal.Width = c(0.246000, 1.23846154 , 1.95714286) ) # Set the sorted attribute for the expected_means to match mean_values setattr(expected_means, 'sorted', 'Species') # Check if the computed mean values match the expected values expect_equal(mean_values, expected_means, info = "Computed means should match expected means") }) })