Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Strip whitespace from column headers in mapping file. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/I-methods.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions inst/tests/test-input-methods.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down