Skip to content

Commit 3a35bd4

Browse files
authored
Merge pull request #530 from moderndive/fix-kable
Fix kable duplicating table headings
2 parents 5f3fb57 + 4826f6b commit 3a35bd4

12 files changed

+65
-65
lines changed

.github/workflows/deploy_bookdown.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
concurrency:
1414
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
1515
env:
16-
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}
16+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1717
EMAIL: ${{ secrets.EMAIL }}
1818
steps:
1919
# Checkout repository
@@ -54,7 +54,7 @@ jobs:
5454
install.packages(c("tidyverse", "bookdown"));
5555
}'
5656
env:
57-
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}
57+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
5858

5959
# Install and cache TinyTeX only if needed
6060
- name: Install TinyTeX if Needed

02-visualization.Rmd

+5-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ In February 2006, a Swedish physician and data advocate named Hans Rosling gave
109109
```{r gapminder-2007, echo=FALSE, purl=FALSE}
110110
gapminder_2007 %>%
111111
head(3) %>%
112-
kable(
112+
kbl(
113113
digits = 2,
114114
caption = "Gapminder 2007 Data: First 3 of 142 countries" # ,
115115
) %>%
@@ -166,7 +166,7 @@ tibble(
166166
aes = c("x", "y", "size", "color"),
167167
geom = c("point", "point", "point", "point")
168168
) %>%
169-
kable(
169+
kbl(
170170
caption = "Summary of the grammar of graphics for this plot",
171171
booktabs = TRUE,
172172
linesep = ""
@@ -881,7 +881,7 @@ Observe in Figure \@ref(fig:flightsbar) that United Airlines (UA), JetBlue Airwa
881881
flights_counted <- flights %>%
882882
group_by(carrier) %>%
883883
summarize(number = n())
884-
kable(flights_counted,
884+
kbl(flights_counted,
885885
digits = 3,
886886
caption = "Number of flights pre-counted for each carrier",
887887
booktabs = TRUE,
@@ -1151,7 +1151,7 @@ if (is_latex_output()) {
11511151
summary_table_ch2 %>%
11521152
# Weird tick marks show up in PDF:
11531153
mutate(`Geometric object` = str_replace_all(`Geometric object`, "`", "")) %>%
1154-
kable(
1154+
kbl(
11551155
caption = "Summary of Five Named Graphs",
11561156
booktabs = TRUE,
11571157
format = "latex",
@@ -1163,7 +1163,7 @@ if (is_latex_output()) {
11631163
column_spec(5, width = "1.6in")
11641164
} else {
11651165
summary_table_ch2 %>%
1166-
kable(
1166+
kbl(
11671167
caption = "Summary of Five Named Graphs",
11681168
booktabs = TRUE,
11691169
format = "html"

03-wrangling.Rmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ Let's take a look at only the `dep_delay`, `arr_delay`, and the resulting `gain`
485485
flights %>%
486486
select(dep_delay, arr_delay, gain) %>%
487487
slice(1:5) %>%
488-
kable(
488+
kbl(
489489
caption = "First five rows of departure/arrival delay and gain variables"
490490
) %>%
491491
kable_styling(position = "center", latex_options = "hold_position")
@@ -872,7 +872,7 @@ if (is_latex_output()) {
872872
Verb = str_replace_all(Verb, "`", ""),
873873
`Data wrangling operation` = str_replace_all(`Data wrangling operation`, "`", ""),
874874
) %>%
875-
kable(
875+
kbl(
876876
caption = "Summary of data wrangling verbs",
877877
booktabs = TRUE,
878878
linesep = "",

04-tidy.Rmd

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ stocks <- tibble(
225225
) %>%
226226
slice(1:2)
227227
stocks %>%
228-
kable(
228+
kbl(
229229
digits = 2,
230230
caption = "Stock prices (non-tidy format)",
231231
booktabs = TRUE,
@@ -253,7 +253,7 @@ stocks_tidy <- stocks %>%
253253
values_to = "Stock Price"
254254
)
255255
stocks_tidy %>%
256-
kable(
256+
kbl(
257257
digits = 2,
258258
caption = "Stock prices (tidy format)",
259259
booktabs = TRUE,
@@ -275,7 +275,7 @@ stocks <- tibble(
275275
) %>%
276276
slice(1:2)
277277
stocks %>%
278-
kable(
278+
kbl(
279279
digits = 2,
280280
caption = "Example of tidy data" # ,
281281
# booktabs = TRUE

05-regression.Rmd

+10-10
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ evals_ch5 %>%
178178
```{r five-random-courses, echo=FALSE, purl=FALSE}
179179
evals_ch5 %>%
180180
sample_n(5) %>%
181-
kable(
181+
kbl(
182182
digits = 3,
183183
caption = "A random sample of 5 out of the 463 courses at UT Austin",
184184
booktabs = TRUE,
@@ -429,7 +429,7 @@ evals_line <- score_model %>%
429429
```
430430
```{r regtable, echo=FALSE, purl=FALSE}
431431
get_regression_table(score_model) %>%
432-
kable(
432+
kbl(
433433
digits = 3,
434434
caption = "Linear regression table",
435435
booktabs = TRUE,
@@ -516,7 +516,7 @@ y_hat <- target_point$score_hat
516516
resid <- target_point$residual
517517
evals_ch5 %>%
518518
slice(index) %>%
519-
kable(
519+
kbl(
520520
digits = 4,
521521
caption = "Data for the 21st course out of 463",
522522
booktabs = TRUE,
@@ -694,7 +694,7 @@ gapminder2007 %>% sample_n(size = 5)
694694
```{r model2-data-preview, echo=FALSE, purl=FALSE}
695695
gapminder2007 %>%
696696
sample_n(5) %>%
697-
kable(
697+
kbl(
698698
digits = 3,
699699
caption = "Random sample of 5 out of 142 countries",
700700
booktabs = TRUE,
@@ -872,7 +872,7 @@ gapminder2007 %>%
872872
group_by(continent) %>%
873873
summarize(mean = mean(lifeExp)) %>%
874874
mutate(`Difference versus Africa` = mean - mean_africa) %>%
875-
kable(
875+
kbl(
876876
digits = 3,
877877
caption = "Mean life expectancy by continent and relative differences from mean for Africa",
878878
booktabs = TRUE,
@@ -916,7 +916,7 @@ lifeExp_model <- lm(lifeExp ~ continent, data = gapminder2007)
916916
```
917917
```{r catxplot4b, echo=FALSE, purl=FALSE}
918918
get_regression_table(lifeExp_model) %>%
919-
kable(
919+
kbl(
920920
digits = 3,
921921
caption = "Linear regression table",
922922
booktabs = TRUE,
@@ -1059,7 +1059,7 @@ regression_points
10591059
regression_points <- get_regression_points(lifeExp_model, ID = "country")
10601060
regression_points %>%
10611061
slice(1:10) %>%
1062-
kable(
1062+
kbl(
10631063
digits = 3,
10641064
caption = "Regression points (First 10 out of 142 countries)",
10651065
booktabs = TRUE,
@@ -1302,7 +1302,7 @@ get_regression_table(score_model)
13021302
```{r recall-table, echo=FALSE, purl=FALSE}
13031303
score_model <- lm(score ~ bty_avg, data = evals_ch5)
13041304
get_regression_table(score_model) %>%
1305-
kable(
1305+
kbl(
13061306
digits = 3,
13071307
caption = "Regression table",
13081308
booktabs = TRUE,
@@ -1341,7 +1341,7 @@ score_model %>%
13411341
lower_ci = conf_low,
13421342
upper_ci = conf_high
13431343
) %>%
1344-
kable(
1344+
kbl(
13451345
digits = 3,
13461346
caption = "Regression table using tidy() from broom package",
13471347
booktabs = TRUE,
@@ -1375,7 +1375,7 @@ score_model %>%
13751375
clean_names() %>%
13761376
select(-c("std_resid", "hat", "sigma", "cooksd", "std_resid")) %>%
13771377
slice(1:10) %>%
1378-
kable(
1378+
kbl(
13791379
digits = 3,
13801380
caption = "Regression points using augment() from broom package",
13811381
booktabs = TRUE,

06-multiple-regression.Rmd

+17-17
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ evals_ch6 %>% sample_n(size = 5)
130130
```{r model4-data-preview, echo=FALSE, purl=FALSE}
131131
evals_ch6 %>%
132132
sample_n(5) %>%
133-
kable(
133+
kbl(
134134
digits = 3,
135135
caption = "A random sample of 5 out of the 463 courses at UT Austin",
136136
booktabs = TRUE,
@@ -221,7 +221,7 @@ lifeExp_model <- lm(lifeExp ~ continent, data = gapminder2007)
221221
222222
# Get regression table and kable output
223223
get_regression_table(lifeExp_model) %>%
224-
kable(
224+
kbl(
225225
digits = 3,
226226
caption = "Regression table for life expectancy as a function of continent",
227227
booktabs = TRUE,
@@ -267,7 +267,7 @@ get_regression_table(score_model_interaction)
267267
```{r regtable-interaction, echo=FALSE, purl=FALSE}
268268
score_model_interaction <- lm(score ~ age * gender, data = evals_ch6)
269269
get_regression_table(score_model_interaction) %>%
270-
kable(
270+
kbl(
271271
digits = 3,
272272
caption = "Regression table for interaction model",
273273
booktabs = TRUE,
@@ -312,7 +312,7 @@ tibble(
312312
Intercept = c(intercept_female, intercept_male),
313313
`Slope for age` = c(slope_female, slope_male)
314314
) %>%
315-
kable(
315+
kbl(
316316
digits = 4,
317317
caption = "Comparison of intercepts and slopes for interaction model",
318318
booktabs = TRUE,
@@ -429,7 +429,7 @@ get_regression_table(score_model_parallel_slopes)
429429
```{r regtable-parallel-slopes, echo=FALSE, purl=FALSE}
430430
score_model_parallel_slopes <- lm(score ~ age + gender, data = evals_ch6)
431431
get_regression_table(score_model_parallel_slopes) %>%
432-
kable(
432+
kbl(
433433
digits = 3,
434434
caption = "Regression table for parallel slopes model",
435435
booktabs = TRUE,
@@ -469,7 +469,7 @@ tibble(
469469
Intercept = c(intercept_female_parallel, intercept_male_parallel),
470470
`Slope for age` = c(age_coef, age_coef)
471471
) %>%
472-
kable(
472+
kbl(
473473
digits = 4,
474474
caption = "Comparison of intercepts and slope for parallel slopes model",
475475
booktabs = TRUE,
@@ -595,7 +595,7 @@ regression_points
595595
regression_points <- get_regression_points(score_model_interaction)
596596
regression_points %>%
597597
slice(1:10) %>%
598-
kable(
598+
kbl(
599599
digits = 3,
600600
caption = "Regression points (First 10 out of 463 courses)" # ,
601601
# booktabs = TRUE
@@ -668,7 +668,7 @@ credit_ch6 %>% sample_n(size = 5)
668668
```{r model3-data-preview, echo=FALSE, purl=FALSE}
669669
credit_ch6 %>%
670670
sample_n(5) %>%
671-
kable(
671+
kbl(
672672
digits = 3,
673673
caption = "Random sample of 5 credit card holders",
674674
booktabs = TRUE,
@@ -720,7 +720,7 @@ credit_ch6 %>%
720720
credit_ch6 %>%
721721
select(debt, credit_limit, income) %>%
722722
cor() %>%
723-
kable(
723+
kbl(
724724
digits = 3,
725725
caption = "Correlation coefficients between credit card debt, credit limit, and income",
726726
booktabs = TRUE,
@@ -874,7 +874,7 @@ debt_model <- lm(debt ~ credit_limit + income, data = credit_ch6)
874874
credit_line <- get_regression_table(debt_model) %>%
875875
pull(estimate)
876876
get_regression_table(debt_model) %>%
877-
kable(
877+
kbl(
878878
digits = 3,
879879
caption = "Multiple regression table",
880880
booktabs = TRUE,
@@ -941,7 +941,7 @@ set.seed(76)
941941
regression_points <- get_regression_points(debt_model)
942942
regression_points %>%
943943
slice(1:10) %>%
944-
kable(
944+
kbl(
945945
digits = 3,
946946
caption = "Regression points (First 10 credit card holders out of 400)",
947947
booktabs = TRUE,
@@ -1062,7 +1062,7 @@ model_2_interaction <- lm(average_sat_math ~ perc_disadvan * size,
10621062
data = MA_schools
10631063
)
10641064
get_regression_table(model_2_interaction) %>%
1065-
kable(
1065+
kbl(
10661066
digits = 3,
10671067
caption = "Interaction model regression table",
10681068
booktabs = TRUE,
@@ -1083,7 +1083,7 @@ model_2_parallel_slopes <- lm(average_sat_math ~ perc_disadvan + size,
10831083
data = MA_schools
10841084
)
10851085
get_regression_table(model_2_parallel_slopes) %>%
1086-
kable(
1086+
kbl(
10871087
digits = 3,
10881088
caption = "Parallel slopes regression table",
10891089
booktabs = TRUE,
@@ -1178,7 +1178,7 @@ bind_rows(
11781178
variances_parallel_slopes
11791179
) %>%
11801180
select(model, var_y, var_y_hat, var_residual, r_squared) %>%
1181-
knitr::kable(
1181+
kbl(
11821182
digits = 3,
11831183
caption = "Comparing variances from interaction and parallel slopes models for MA school data",
11841184
booktabs = TRUE,
@@ -1205,7 +1205,7 @@ bind_rows(
12051205
variances_parallel_slopes
12061206
) %>%
12071207
select(model, var_y, var_y_hat, var_residual, r_squared) %>%
1208-
knitr::kable(
1208+
kbl(
12091209
digits = 3,
12101210
caption = "Comparing variances from interaction and parallel slopes models for UT Austin data",
12111211
booktabs = TRUE,
@@ -1244,7 +1244,7 @@ credit_ch6 %>%
12441244
select(debt, income) %>%
12451245
mutate(income = income * 1000) %>%
12461246
cor() %>%
1247-
kable(
1247+
kbl(
12481248
digits = 3,
12491249
caption = "Correlation between income (in dollars) and credit card debt",
12501250
booktabs = TRUE,
@@ -1274,7 +1274,7 @@ debt_model <- lm(debt ~ credit_limit + income, data = credit_ch6)
12741274
credit_line <- get_regression_table(debt_model) %>%
12751275
pull(estimate)
12761276
get_regression_table(debt_model) %>%
1277-
kable(
1277+
kbl(
12781278
digits = 3,
12791279
caption = "Multiple regression results",
12801280
booktabs = TRUE,

07-sampling.Rmd

+5-5
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ comparing_n_table <- virtual_prop %>%
621621
rename(`Number of slots in shovel` = n, `Standard deviation of proportions red` = sd)
622622
623623
comparing_n_table %>%
624-
kable(
624+
kbl(
625625
digits = 3,
626626
caption = "Comparing standard deviations of proportions red for three different shovels",
627627
booktabs = TRUE,
@@ -817,7 +817,7 @@ comparing_n_table <- virtual_prop %>%
817817
rename(`Number of slots in shovel` = n, `Standard deviation of proportions red` = sd)
818818
819819
comparing_n_table %>%
820-
kable(
820+
kbl(
821821
digits = 3,
822822
caption = "Previously seen comparing standard deviations of proportions red for three different shovels",
823823
booktabs = TRUE,
@@ -873,7 +873,7 @@ comparing_n_table <- virtual_prop %>%
873873
rename(`Sample size (n)` = n, `Standard error of $\\widehat{p}$` = sd)
874874
875875
comparing_n_table %>%
876-
kable(
876+
kbl(
877877
digits = 3,
878878
caption = "Standard errors of the sample proportion based on sample sizes of 25, 50, and 100",
879879
booktabs = TRUE,
@@ -985,7 +985,7 @@ comparing_n_table <- virtual_prop %>%
985985
sample_frac(1)
986986
987987
comparing_n_table %>%
988-
kable(
988+
kbl(
989989
digits = 3,
990990
caption = "Standard errors of $\\widehat{p}$ based on n = 25, 50, 100",
991991
booktabs = TRUE,
@@ -1177,7 +1177,7 @@ if (!file.exists("rds/sampling_scenarios.rds")) {
11771177
}
11781178
11791179
sampling_scenarios %>%
1180-
kable(
1180+
kbl(
11811181
caption = "\\label{tab:summarytable-ch8}Scenarios of sampling for inference",
11821182
booktabs = TRUE,
11831183
escape = FALSE,

0 commit comments

Comments
 (0)