option to add_indent spacing to any column
diff --git a/tests/testthat/test-indent-html.R b/tests/testthat/test-indent-html.R
new file mode 100644
index 0000000..1b4830b
--- /dev/null
+++ b/tests/testthat/test-indent-html.R
@@ -0,0 +1,39 @@
+context("add_indent")
+
+test_that("add_indent can add to 1 row", {
+ observed <- kable(mtcars[1:4, 1:3], "html") %>%
+ add_indent(1) %>%
+ as.character()
+ expected <- "<table>\n <thead>\n <tr>\n <th style=\"text-align:left;\"> </th>\n <th style=\"text-align:right;\"> mpg </th>\n <th style=\"text-align:right;\"> cyl </th>\n <th style=\"text-align:right;\"> disp </th>\n </tr>\n </thead>\n<tbody>\n <tr>\n <td style=\"text-align:left;padding-left: 2em;\" indentlevel=\"1\"> Mazda RX4 </td>\n <td style=\"text-align:right;\"> 21.0 </td>\n <td style=\"text-align:right;\"> 6 </td>\n <td style=\"text-align:right;\"> 160 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Mazda RX4 Wag </td>\n <td style=\"text-align:right;\"> 21.0 </td>\n <td style=\"text-align:right;\"> 6 </td>\n <td style=\"text-align:right;\"> 160 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Datsun 710 </td>\n <td style=\"text-align:right;\"> 22.8 </td>\n <td style=\"text-align:right;\"> 4 </td>\n <td style=\"text-align:right;\"> 108 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Hornet 4 Drive </td>\n <td style=\"text-align:right;\"> 21.4 </td>\n <td style=\"text-align:right;\"> 6 </td>\n <td style=\"text-align:right;\"> 258 </td>\n </tr>\n</tbody>\n</table>"
+ expect_equal(observed, expected)
+})
+
+test_that("add_indent can be added multiple times.", {
+ observed <- kable(mtcars[1:4, 1:3], "html") %>%
+ add_indent(1:3) %>%
+ add_indent(1) %>%
+ as.character()
+ expected <- "<table>\n <thead>\n <tr>\n <th style=\"text-align:left;\"> </th>\n <th style=\"text-align:right;\"> mpg </th>\n <th style=\"text-align:right;\"> cyl </th>\n <th style=\"text-align:right;\"> disp </th>\n </tr>\n </thead>\n<tbody>\n <tr>\n <td style=\"text-align:left;padding-left: 4em;\" indentlevel=\"2\"> Mazda RX4 </td>\n <td style=\"text-align:right;\"> 21.0 </td>\n <td style=\"text-align:right;\"> 6 </td>\n <td style=\"text-align:right;\"> 160 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;padding-left: 2em;\" indentlevel=\"1\"> Mazda RX4 Wag </td>\n <td style=\"text-align:right;\"> 21.0 </td>\n <td style=\"text-align:right;\"> 6 </td>\n <td style=\"text-align:right;\"> 160 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;padding-left: 2em;\" indentlevel=\"1\"> Datsun 710 </td>\n <td style=\"text-align:right;\"> 22.8 </td>\n <td style=\"text-align:right;\"> 4 </td>\n <td style=\"text-align:right;\"> 108 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Hornet 4 Drive </td>\n <td style=\"text-align:right;\"> 21.4 </td>\n <td style=\"text-align:right;\"> 6 </td>\n <td style=\"text-align:right;\"> 258 </td>\n </tr>\n</tbody>\n</table>"
+ expect_equal(observed, expected)
+})
+
+test_that("add_indent can add to an interior column.", {
+ cars <- mtcars[1:4, 1:3]
+ cars$cyl <- as.character(cars$cyl)
+ observed <- kable(cars, "html") %>%
+ add_indent(1:3, target_cols = 3) %>%
+ as.character()
+ expected <- "<table>\n <thead>\n <tr>\n <th style=\"text-align:left;\"> </th>\n <th style=\"text-align:right;\"> mpg </th>\n <th style=\"text-align:left;\"> cyl </th>\n <th style=\"text-align:right;\"> disp </th>\n </tr>\n </thead>\n<tbody>\n <tr>\n <td style=\"text-align:left;\"> Mazda RX4 </td>\n <td style=\"text-align:right;\"> 21.0 </td>\n <td style=\"text-align:left;padding-left: 2em;\" indentlevel=\"1\"> 6 </td>\n <td style=\"text-align:right;\"> 160 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Mazda RX4 Wag </td>\n <td style=\"text-align:right;\"> 21.0 </td>\n <td style=\"text-align:left;padding-left: 2em;\" indentlevel=\"1\"> 6 </td>\n <td style=\"text-align:right;\"> 160 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Datsun 710 </td>\n <td style=\"text-align:right;\"> 22.8 </td>\n <td style=\"text-align:left;padding-left: 2em;\" indentlevel=\"1\"> 4 </td>\n <td style=\"text-align:right;\"> 108 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Hornet 4 Drive </td>\n <td style=\"text-align:right;\"> 21.4 </td>\n <td style=\"text-align:left;\"> 6 </td>\n <td style=\"text-align:right;\"> 258 </td>\n </tr>\n</tbody>\n</table>"
+ expect_equal(observed, expected)
+})
+
+test_that("add_indent can add to an interior column multiple times.", {
+ cars <- mtcars[1:4, 1:3]
+ cars$cyl <- as.character(cars$cyl)
+ observed <- kable(cars, "html") %>%
+ add_indent(1:3, target_cols = 3) %>%
+ add_indent(1, target_cols = 3) %>%
+ as.character()
+ expected <- "<table>\n <thead>\n <tr>\n <th style=\"text-align:left;\"> </th>\n <th style=\"text-align:right;\"> mpg </th>\n <th style=\"text-align:left;\"> cyl </th>\n <th style=\"text-align:right;\"> disp </th>\n </tr>\n </thead>\n<tbody>\n <tr>\n <td style=\"text-align:left;\"> Mazda RX4 </td>\n <td style=\"text-align:right;\"> 21.0 </td>\n <td style=\"text-align:left;padding-left: 4em;\" indentlevel=\"2\"> 6 </td>\n <td style=\"text-align:right;\"> 160 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Mazda RX4 Wag </td>\n <td style=\"text-align:right;\"> 21.0 </td>\n <td style=\"text-align:left;padding-left: 2em;\" indentlevel=\"1\"> 6 </td>\n <td style=\"text-align:right;\"> 160 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Datsun 710 </td>\n <td style=\"text-align:right;\"> 22.8 </td>\n <td style=\"text-align:left;padding-left: 2em;\" indentlevel=\"1\"> 4 </td>\n <td style=\"text-align:right;\"> 108 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Hornet 4 Drive </td>\n <td style=\"text-align:right;\"> 21.4 </td>\n <td style=\"text-align:left;\"> 6 </td>\n <td style=\"text-align:right;\"> 258 </td>\n </tr>\n</tbody>\n</table>"
+ expect_equal(observed, expected)
+})
diff --git a/tests/testthat/test-indent-latex.R b/tests/testthat/test-indent-latex.R
index 84d9fec..241ea82 100644
--- a/tests/testthat/test-indent-latex.R
+++ b/tests/testthat/test-indent-latex.R
@@ -17,4 +17,19 @@
expect_equal(observed, expected)
})
+test_that("add_indent can add to an interior column.", {
+ observed <- kable(mtcars[1:4, 1:3], "latex") %>%
+ add_indent(1:3, target_cols = 2) %>%
+ as.character()
+ expected <- "\n\\begin{tabular}{l|r|r|r}\n\\hline\n & mpg & cyl & disp\\\\\n\\hline\nMazda RX4 & \\hspace{1em}21.0 & 6 & 160\\\\\n\\hline\nMazda RX4 Wag & \\hspace{1em}21.0 & 6 & 160\\\\\n\\hline\nDatsun 710 & \\hspace{1em}22.8 & 4 & 108\\\\\n\\hline\nHornet 4 Drive & 21.4 & 6 & 258\\\\\n\\hline\n\\end{tabular}"
+ expect_equal(observed, expected)
+})
+test_that("add_indent can add to an interior column multiple times.", {
+ observed <- kable(mtcars[1:4, 1:3], "latex") %>%
+ add_indent(1:3, target_cols = 2) %>%
+ add_indent(1, target_cols = 2) %>%
+ as.character()
+ expected <- "\n\\begin{tabular}{l|r|r|r}\n\\hline\n & mpg & cyl & disp\\\\\n\\hline\nMazda RX4 & \\hspace{1em}\\hspace{1em}21.0 & 6 & 160\\\\\n\\hline\nMazda RX4 Wag & \\hspace{1em}21.0 & 6 & 160\\\\\n\\hline\nDatsun 710 & \\hspace{1em}22.8 & 4 & 108\\\\\n\\hline\nHornet 4 Drive & 21.4 & 6 & 258\\\\\n\\hline\n\\end{tabular}"
+ expect_equal(observed, expected)
+})