diff --git a/R/print.data.table.R b/R/print.data.table.R index d53855d79d..96f3e8060c 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -15,6 +15,8 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), # trunc.cols - should only the columns be printed that can fit in the console? (FALSE) if (!col.names %chin% c("auto", "top", "none")) stop("Valid options for col.names are 'auto', 'top', and 'none'") + if (length(trunc.cols) != 1L || !is.logical(trunc.cols) || is.na(trunc.cols)) + stop("Valid options for trunc.cols are TRUE and FALSE") if (col.names == "none" && class) warning("Column classes will be suppressed when col.names is 'none'") if (!shouldPrint(x)) { diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index ef23279700..88465242c7 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -17319,3 +17319,10 @@ if (identical(text, enc2native(text))) { # ensure native encoding can represent } test(2167.3, fwrite(dt, csvfile, encoding="nativ"), error="Argument 'encoding' must be") unlink(csvfile) + +# check valid trunc.cols=, #4766 +DT = data.table(x = rnorm(10)) +test(2168.01, print(DT, trunc.cols = 5L), error=c("Valid options for trunc.cols are TRUE and FALSE")) +test(2168.02, print(DT, trunc.cols = NA), error=c("Valid options for trunc.cols are TRUE and FALSE")) +test(2168.03, print(DT, trunc.cols = "thing"), error=c("Valid options for trunc.cols are TRUE and FALSE")) +test(2168.04, print(DT, trunc.cols = c(TRUE, FALSE)), error=c("Valid options for trunc.cols are TRUE and FALSE"))