The {qtkit} package provides several functions to help publish analysis artifacts in a standardized way:
write_kbl(): Save kable/kableExtra tables to fileswrite_gg(): Save ggplot2 plots to fileswrite_obj(): Save R objects to filesThese functions handle common tasks like:
Let’s create and save a simple table using
write_kbl():
You can customize the output format and styling:
Save ggplot2 plots with write_gg():
Add custom themes and formatting:
p <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) +
geom_point(size = 3) +
theme_minimal() +
labs(
title = "Car Weight vs Fuel Efficiency",
x = "Weight (1000 lbs)",
y = "Miles per Gallon",
color = "Cylinders"
)
write_gg(
gg_obj = p,
file = "mtcars_plot_styled",
target_dir = "artifacts/",
device = "png",
width = 8,
height = 6,
dpi = 300
)Use write_obj() to save R objects for later use:
Tables and plots saved with {qtkit} can be easily restored from the
directory where they have been saved (in this case
artifacts/). For image formats, you can use the
knitr::include_graphics() function, markdown, or HTML:
Objects can be read back using dget():
# Read the saved object
restored_data <- dget("artifacts/mtcars_4cyl")
# Check the restored object
glimpse(restored_data)
#> Rows: 11
#> Columns: 3
#> $ mpg <dbl> 22.8, 24.4, 22.8, 32.4, 30.4, 33.9, 21.5, 27.3, 26.0, 30.4, 21.4
#> $ wt <dbl> 2.320, 3.190, 3.150, 2.200, 1.615, 1.835, 2.465, 1.935, 2.140, 1.5…
#> $ hp <dbl> 93, 62, 95, 66, 52, 65, 97, 66, 91, 113, 109Tip Note that tables and plots need not be saved with the
write_kbl()andwrite_gg()functions to be restored. These objects can be saved and restored using thewrite_obj()anddget()function as well.
help(package = "qtkit")