diff --git a/src/column.cpp b/src/column.cpp index 1729f42..3f43a9e 100644 --- a/src/column.cpp +++ b/src/column.cpp @@ -171,7 +171,7 @@ RObject columnsToDf(std::vector columns, Rcpp::CharacterVector names, if (columns[i]->has_failures()) { std::string message = columns[i]->describe_failures( Rcpp::as(names[static_cast(i)])); - Rf_warning(message.c_str()); + Rf_warning("%s", message.c_str()); } out[static_cast(i)] = columns[i]->vector(); } diff --git a/tests/testthat/test-coltype-warning.R b/tests/testthat/test-coltype-warning.R new file mode 100644 index 0000000..3e6d85a --- /dev/null +++ b/tests/testthat/test-coltype-warning.R @@ -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" + ) +})