Thanks. When using kable, I am able to print the variable label in the caption of a table with caption = var_label(gss_cat$partyid). When calling the qtab function defined above (the user defined function?) with caption = var_label(df$x), the label does not print. The warning, which prints when knitting the above reprex in RMarkdown, is: Warning: Unknown or uninitialised column: x. I've tried various alternatives to df$x without success.
gss_cat is a built into forcats and is loaded with the tidyverse.
library(tidyverse)
head(gss_cat)
#> # A tibble: 6 x 9
#> year marital age race rincome partyid relig denom tvhours
#> <int> <fct> <int> <fct> <fct> <fct> <fct> <fct> <int>
#> 1 2000 Never mar… 26 White $8000 to … Ind,near r… Protesta… Souther… 12
#> 2 2000 Divorced 48 White $8000 to … Not str re… Protesta… Baptist… NA
#> 3 2000 Widowed 67 White Not appli… Independent Protesta… No deno… 2
#> 4 2000 Never mar… 39 White Not appli… Ind,near r… Orthodox… Not app… 4
#> 5 2000 Divorced 25 White Not appli… Not str de… None Not app… 1
#> 6 2000 Married 25 White $20000 - … Strong dem… Protesta… Souther… NA
Created on 2021-07-26 by the reprex package (v0.3.0)
Thanks again