How about teaching something like this (works interactively, in knitr, and in reprex):
v <- function(x, title = as.character(substitute(x)), n = 20) {
if(interactive()) {
View(x, title = title)
} else {
knitr::kable(head(x, n = n), caption = title)
}
}
v(mtcars)
I've added a note on this here.