Skip to content

Commit fd6ef99

Browse files
committed
Use normal output instead of message
1 parent 078d23d commit fd6ef99

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

R/getInspectionRecords_v2.R

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,39 +125,42 @@ textblockToDataframe <- function(
125125
}
126126

127127
# getColumnsToRemove -----------------------------------------------------------
128+
#' @importFrom kwb.utils allAreEqual catIf printIf stringList
128129
getColumnsToRemove <- function(x, captions, duplicates, dbg = TRUE)
129130
{
131+
catIf <- kwb.utils::catIf
132+
130133
columnsToRemove <- numeric()
131134

132135
for (duplicate in duplicates) {
133136

134-
message("Column '", duplicate, "' exists multiple times!")
137+
catIf(dbg, sprintf("Column '%s' exists multiple times!\n", duplicate))
135138

136139
columns <- which(captions == duplicate)
137140

138141
allEqualInRow <- apply(x[, columns], MARGIN = 1, kwb.utils::allAreEqual)
139142

140143
if (all(allEqualInRow)) {
141144

142-
columnsToRemove <- c(columnsToRemove, columns[-1])
145+
columnsToRemove <- c(columnsToRemove, columns[-1L])
143146

144-
message(
145-
"For each row, the values in the duplicated rows are equal ",
146-
"-> I removed the duplicated columns!"
147+
catIf(
148+
dbg, "For each row, the values in the duplicated rows are equal ",
149+
"-> I removed the duplicated columns.\n"
147150
)
148151

149152
if (dbg) {
150-
151-
cat("The values in the duplicated columns are:\n")
152-
153-
x.output <- x[, columns]
154-
155-
print(x.output[! duplicated(x.output), ])
153+
x.out <- x[, columns]
154+
kwb.utils::printIf(
155+
TRUE,
156+
x = x.out[! duplicated(x.out), ],
157+
caption = "The values in the duplicated columns are"
158+
)
156159
}
157160
}
158161

159-
kwb.utils::catIf(
160-
dbg && length(columnsToRemove) > 0,
162+
catIf(
163+
dbg && length(columnsToRemove),
161164
"columnsToRemove:", kwb.utils::stringList(columnsToRemove), "\n"
162165
)
163166
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#library(testthat)
2+
13
test_that("cleanDuplicatedColumns() works", {
24

35
f <- kwb.en13508.2:::cleanDuplicatedColumns
@@ -6,7 +8,7 @@ test_that("cleanDuplicatedColumns() works", {
68

79
x <- data.frame(a.x = 1:2, a.y = 1:2, id = 1:2)
810

9-
expect_output(result <- f(x))
11+
expect_message(capture.output(result <- f(x)))
1012

1113
expect_identical(result, stats::setNames(x[, -2L, ], c("a", "id")))
1214
})

0 commit comments

Comments
 (0)