tests/testthat/test_dtapply.R

context("dtapply")

NMdataConf(reset=TRUE)

test_that("basic - return single value",{
    fileRef <- "testReference/dtapply_01.rds"

    res <- dtapply(1:3,function(x)paste0("x",x))
    
    expect_equal_to_reference(res,fileRef)

    if(FALSE){
        ref <- readRDS(fileRef)
        ref
        res
    }
})

test_that("return dt",{
    fileRef <- "testReference/dtapply_02.rds"
    res <- dtapply(1:3,function(x)list(hey=paste(x)))
    expect_equal_to_reference(res,fileRef)

    if(FALSE){
        ref <- readRDS(fileRef)
        ref
        res
    }
})


test_that("rename columns",{
    fileRef <- "testReference/dtapply_03.rds"
    res <- dtapply(1:3,function(x)paste0("x",x), value.names="val",element.name="x")
    expect_equal_to_reference(res,fileRef)
})

Try the NMdata package in your browser

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

NMdata documentation built on Nov. 5, 2025, 5:43 p.m.