tests/testthat/test-IO.R

library(testthat)
library(phyloseq)
library(rlang)
library(micrec)
library(tibble)

context("Testing importing io for recipe type objects")
data(GlobalPatterns, package = "phyloseq") # data set with phylogenetic tree
data(enterotype, package = "phyloseq")

test_that("extract_vars extracts the right data", {
  mix <- c(taxa_names(enterotype)[2:10], "Nationality","Gender", "Age")
  none <- paste0("Tax",1:10)
  df <- extract_vars(enterotype, mix)
  df2 <- extract_vars(enterotype, none)
  not_phyloseq <- matrix(rnorm(1000), nrow = 10, ncol = 10)
  expect_true(is_tibble(df))
  expect_equal(ncol(df), length(mix))
  expect_equal(nrow(df), nsamples(enterotype))
  expect_error(extract_vars(not_phyloseq, mix))
  expect_identical(df2, tibble(samp_id = sample_names(enterotype)))
})
quangnguyen1995/micrec documentation built on March 2, 2020, 12:12 a.m.