test_that("ragged names blank all factor columns rather than filling partially", { d <- data.frame(sim = c("A_Rice_AWD_N120", "A-Rice-AWD-N30"), stringsAsFactors = FALSE) r <- suppressWarnings(set_factors(d, parts = c("site", "crop", "water", "N"))) expect_equal(r$site[1], "A") expect_true(is.na(r$site[2])) }) test_that("numeric_from strips the prefix", { d <- data.frame(sim = c("A_N0", "A_N120"), stringsAsFactors = FALSE) r <- set_factors(d, parts = c("site", "N"), numeric_from = "N") expect_true(is.numeric(r$N)); expect_equal(sort(r$N), c(0, 120)) }) test_that("detect_factors finds the separator and constant fields", { s <- c("G_Rice_AWD_N0", "G_Rice_CF_N120", "B_Rice_AWD_N60") det <- detect_factors(s) expect_equal(det$sep, "_"); expect_equal(det$n_fields, 4) expect_true(2 %in% det$constant) })