From 33fe16e4ceca77069e9c0c58cc366b47ee696e85 Mon Sep 17 00:00:00 2001 From: TysonStanley Date: Sun, 18 Oct 2020 16:47:54 -0600 Subject: [PATCH 1/8] add check for trunc.cols --- R/print.data.table.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/print.data.table.R b/R/print.data.table.R index ba17e5888d..be7e727b9d 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 (!is.logical(trunc.cols)) + stop("Valid options for trunc.cols are TRUE or FALSE") if (col.names == "none" && class) warning("Column classes will be suppressed when col.names is 'none'") if (!shouldPrint(x)) { From 82c8ae6288ca1483ab9a86516e517c24e31ae360 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 18 Oct 2020 20:58:00 -0400 Subject: [PATCH 2/8] tweak grammar --- R/print.data.table.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index be7e727b9d..7488ac113f 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -16,7 +16,7 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), if (!col.names %chin% c("auto", "top", "none")) stop("Valid options for col.names are 'auto', 'top', and 'none'") if (!is.logical(trunc.cols)) - stop("Valid options for trunc.cols are TRUE or FALSE") + 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)) { From 34aded29f7ad618c9702be41cbbb1739084958ff Mon Sep 17 00:00:00 2001 From: TysonStanley Date: Mon, 19 Oct 2020 19:40:32 -0600 Subject: [PATCH 3/8] added check for NA --- R/print.data.table.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index 7488ac113f..3d969af1c0 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -15,7 +15,7 @@ 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 (!is.logical(trunc.cols)) + if (!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'") From 85bd5526452ef2186a69c9263356bc035d556b61 Mon Sep 17 00:00:00 2001 From: TysonStanley Date: Mon, 19 Oct 2020 21:01:23 -0600 Subject: [PATCH 4/8] typo --- R/print.data.table.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index 3d969af1c0..530aaff5d4 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -15,7 +15,7 @@ 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 (!is.logical(trunc.cols) | !is.na(trunc.cols)) + if (!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'") From a24346e9b1fad5e9ed3acc0e57212bd5f0eb74fb Mon Sep 17 00:00:00 2001 From: TysonStanley Date: Mon, 19 Oct 2020 21:06:57 -0600 Subject: [PATCH 5/8] add three small tests for trunc.cols check --- inst/tests/tests.Rraw | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 3233c4f94b..69dc7e983c 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16726,6 +16726,11 @@ DT = data.table( s4class(x=2L, y="yes", z=1))) test(2130.03, print(DT), output=c(" x y", "1: 1 ", "2: 2 ")) +# error check for trunc.cols +DT = data.table(x = rnorm(10)) +test(2131.01, print(DT, trunc.cols = 5L), error=c("Valid options for trunc.cols are TRUE and FALSE")) +test(2131.02, print(DT, trunc.cols = NA), error=c("Valid options for trunc.cols are TRUE and FALSE")) +test(2131.03, print(DT, trunc.cols = "thing"), error=c("Valid options for trunc.cols are TRUE and FALSE")) ######################## # Add new tests here # From e89b1ddcbba7677400b73897584f7a6ab49b1ad0 Mon Sep 17 00:00:00 2001 From: TysonStanley Date: Tue, 20 Oct 2020 00:45:38 -0600 Subject: [PATCH 6/8] update check --- R/print.data.table.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index 530aaff5d4..283c2c2d9a 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -15,7 +15,7 @@ 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 (!is.logical(trunc.cols) | is.na(trunc.cols)) + if (length(trunc.cols) != 1 || !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'") From 91bee93f330ec812027e686cce75e2500f8e00fb Mon Sep 17 00:00:00 2001 From: TysonStanley Date: Tue, 20 Oct 2020 00:46:13 -0600 Subject: [PATCH 7/8] add check for length != 1 trunc.cols --- inst/tests/tests.Rraw | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 69dc7e983c..f011f270fb 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16731,6 +16731,7 @@ DT = data.table(x = rnorm(10)) test(2131.01, print(DT, trunc.cols = 5L), error=c("Valid options for trunc.cols are TRUE and FALSE")) test(2131.02, print(DT, trunc.cols = NA), error=c("Valid options for trunc.cols are TRUE and FALSE")) test(2131.03, print(DT, trunc.cols = "thing"), error=c("Valid options for trunc.cols are TRUE and FALSE")) +test(2131.04, print(DT, trunc.cols = c(TRUE, FALSE)), error=c("Valid options for trunc.cols are TRUE and FALSE")) ######################## # Add new tests here # From 8f366a935705bc4fcfb0d1d85ee2563b1c55bdac Mon Sep 17 00:00:00 2001 From: Matt Dowle Date: Thu, 15 Apr 2021 16:13:27 -0600 Subject: [PATCH 8/8] 1 => 1L --- R/print.data.table.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index 3f974f67fa..96f3e8060c 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -15,7 +15,7 @@ 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) != 1 || !is.logical(trunc.cols) || is.na(trunc.cols)) + 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'")