context("HTML imports/exports")

test_that("Export to HTML", {
    expect_true(export(iris, "iris.html") %in% dir(), label = "export to html works")

test_that("Export to HTML with ampersands",{
  iris$`R & D` <- paste(sample(letters,nrow(iris),rep=T),
  expect_true(export(iris, "iris2.html") %in% dir(), 
              label = "export to html with ampersands works")

test_that("Import from HTML", {
    expect_true(is.data.frame(import("iris.html")), label = "import from single-table html works")
    f <- system.file("examples", "twotables.html", package = "rio")
    expect_true(all(dim(import(f, which = 1)) == c(32, 11)), label = "import from two-table html works (which = 1)")
    expect_true(all(dim(import(f, which = 2)) == c(150, 5)), label = "import from two-table html works (which = 2)")

test_that("Import from HTML with multiple tbody elements", {
    expect_true(is.data.frame(import("files/two-tbody.html")), label="import with two tbody elements in a single html table works")
    expect_true(is.data.frame(import("files/br-in-header.html")), label="import with an empty header cell in an html table works")
    expect_true(is.data.frame(import("files/br-in-td.html")), label="import with an empty data cell in a single html table works")
    expect_true(is.data.frame(import("files/th-as-row-element.html")), label="import with th instead of td in a non-header row in a single html table works")

unlink(c("iris.xml", "iris2.xml", "iris2.html"))

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.