-
Notifications
You must be signed in to change notification settings - Fork 122
Description
Hello,
I'm attempting to use chrome_print() in a function that saves a gt_tbl object as html and as pdf. When looping through multiple gt_tbl objects, I'm getting this error message, and I don't know where it's coming from.
[2025-06-24 16:39:52] [error] handle_read_frame error: asio.system:10054 (An existing connection was forcibly closed by the remote host.)
This error doesn't show up when I don't use the gt_to_pdf() function on its own. It seems to only happen when I'm using it in a loop.
The directory I'm saving to is on Sharepoint/OneDrive.
The pdf files are created just fine even though the error message shows up on about half of the loops. But, I ran into an issue where RStudio fatally crashed after receiving this error several times.
This is the function I'm using:**
gt_to_pdf <- function (gt,fname, html_dir = paste0(getwd(),"/"),scale = 1, render_exist = FALSE){
if ("gt_tbl" %!in% class(gt)){
stop("gt argument must be a gt object")
}
gt_html = gt%>%as_raw_html()
gt_html_fpath = html_dir%&%fname%&%".html"
gt_pdf_fpath = html_dir%&%fname%&%".pdf"
write_file(gt_html,gt_html_fpath)
if (requireNamespace("pagedown", quietly = TRUE)) {
if (!is.null(fname)) {
pagedown::chrome_print(input = gt_html_fpath,output = gt_pdf_fpath, options = list(scale = scale),timeout = 45,format = "pdf",verbose = 0)
}
else {
stop("specify the filename you want to use. Do not include suffix")
}
}
else {
stop("Please install.packages('pagedown')")
}
}
Here's how I'm using the function in the loop:
for (j in 1:length(programs_of_study)){
program = gsub(" ","",remove_punctuation(programs_of_study[j]))
l_part_a = get(program%&%"_A")
l_part_b = get(program%&%"_B")
l_part_c = get(program%&%"_C")
l_html = l_part_a%>%
tab_footnote(footnote = l_part_b)%>%
tab_footnote(footnote = l_part_c)
gt_to_pdf(l_html,program,html_dir = html_path)
}