tests/testthat/test_format_rds.R

context("Rds imports/exports")
require("datasets")

test_that("Export to rds", {
    expect_true(export(iris, "iris.rds") %in% dir())
})

test_that("Import from rds", {
    expect_true(is.data.frame(import("iris.rds")))
    expect_warning(import("iris.rds", invalid_argument=42),
                   "File imported using readRDS. Arguments to '...' ignored.",
                   label="rda imports and ignores unused arguments with a warning")
})

test_that("Export to rds (non-data frame)", {
    expect_true(export(list(1:10, letters), "list.rds") %in% dir())
    expect_true(inherits(import("list.rds"), "list"))
    expect_true(length(import("list.rds")) == 2L)
})

unlink("iris.rds")
unlink("list.rds")

Try the rio package in your browser

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

rio documentation built on Nov. 22, 2021, 9:07 a.m.