tests/testthat/test_cache.R

test_that("works as expected", {
  
    if('qs' %in% utils::installed.packages()){
        
        cache.init(
        
        at.path = tempdir(),
        verbose = FALSE,
        
        caches = list(

            list(
                name = 'cache',
                depends.on = c( 'test-files' )
            ),
            
            list(
                name = 'cache',
                depends.on = c( 'test-files' )
            )
            
        )

        )

        expect_equal( cache.ok(1), FALSE )
        expect_equal( cache.ok(2), FALSE )
        
        expect_equal( cache.ok(1), FALSE )
        save.cache( iris )
        expect_equal( cache.ok(1), TRUE )
        expect_equal( cache.ok(2), FALSE )
        
        save.cache( iris )
        expect_equal( cache.ok(1), TRUE )
        expect_equal( cache.ok(2), TRUE )
        
        clear.cache(2)
        expect_equal( cache.ok(1), TRUE )
        clear.cache()
        
        expect_equal( cache.ok(1), FALSE )

    }
  
})

Try the easyr package in your browser

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

easyr documentation built on March 31, 2023, 6:22 p.m.