diff --git a/R/I-methods.r b/R/I-methods.r index 021c6ad..e9896ca 100644 --- a/R/I-methods.r +++ b/R/I-methods.r @@ -161,7 +161,7 @@ # read the header f <- file(filepath, 'r') header <- scan(filepath, what='character', sep='\t', comment.char='', - skip=header.index-1, quote='"', + skip=header.index-1, quote='"', strip.white=TRUE, nlines=1, quiet=TRUE) # Close the connection close(f) diff --git a/inst/tests/test-input-methods.r b/inst/tests/test-input-methods.r index 4f97dce..65c166c 100644 --- a/inst/tests/test-input-methods.r +++ b/inst/tests/test-input-methods.r @@ -58,6 +58,19 @@ test_that("Whitespace is stripped from fields in mapping file", { unlink(map_fp) }) +test_that("Whitespace is stripped from column names in mapping file", { + map_fp <- tempfile() + writeLines(c("#SampleID\t A\tB C ", "w\tx\ty"), map_fp) + + expected_df <- data.frame("x", "y") + rownames(expected_df) <- "w" + colnames(expected_df) <- c("A", "B C") + + expect_equal(load.qiime.mapping.file(map_fp), expected_df) + + unlink(map_fp) +}) + test_that("Comments are ignored in mapping file", { map_fp <- tempfile() writeLines(c("#SampleID\tA\tB", "# Comment 1", "w\tx\ty", "#C2"), map_fp)