Skip to content

Commit

Permalink
Add test for bad column type warning, and fix call to Rf_warning() th…
Browse files Browse the repository at this point in the history
…at generates that warning
  • Loading branch information
dtburk committed Nov 29, 2023
1 parent 4833196 commit bf3906d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ RObject columnsToDf(std::vector<ColumnPtr> columns, Rcpp::CharacterVector names,
if (columns[i]->has_failures()) {
std::string message = columns[i]->describe_failures(
Rcpp::as<std::string>(names[static_cast<long>(i)]));
Rf_warning(message.c_str());
Rf_warning("%s", message.c_str());
}
out[static_cast<long>(i)] = columns[i]->vector();
}
Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/test-coltype-warning.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
test_that("bad column types generates warning", {
expect_warning(
hipread_long(
hipread_example("test-basic.dat"),
list(
H = hip_fwf_widths(
c(1, 3, 3, 3, 2),
c("rt", "hhnum", "hh_char", "hh_dbl", "hh_impdbl"),
# Misspecify hh_char as a double type
c("character", "character", "double", "double", "double"),
trim_ws = c(TRUE, FALSE, TRUE, NA, NA),
imp_dec = c(NA, NA, NA, 0, 1)
),
P = hip_fwf_widths(
c(1, 3, 1, 3, 1),
c("rt", "hhnum", "pernum", "per_dbl", "per_mix"),
c("character", "character", "integer", "double", "character"),
trim_ws = c(TRUE, FALSE, NA, NA, TRUE),
imp_dec = c(NA, NA, NA, 0, NA)
)
),
hip_rt(1, 1)
),
regexp = "could not convert"
)
})

0 comments on commit bf3906d

Please sign in to comment.