From 5fbfa2aaca0cef707fa18e6ecba42a5d84356295 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 28 Apr 2023 11:49:41 -0400 Subject: [PATCH 1/9] Add example of HTML render from Quarto to inst --- .../quarto-report-render.html | 3331 +++++++++++++++++ 1 file changed, 3331 insertions(+) create mode 100644 inst/quarto_example_documents/quarto-report-render.html diff --git a/inst/quarto_example_documents/quarto-report-render.html b/inst/quarto_example_documents/quarto-report-render.html new file mode 100644 index 00000000..03c6409f --- /dev/null +++ b/inst/quarto_example_documents/quarto-report-render.html @@ -0,0 +1,3331 @@ + + + + + + + + + +report + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+
library(tidyverse)
+
+
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
+✔ dplyr     1.1.1     ✔ readr     2.1.4
+✔ forcats   1.0.0     ✔ stringr   1.5.0
+✔ ggplot2   3.4.1     ✔ tibble    3.2.1
+✔ lubridate 1.9.2     ✔ tidyr     1.3.0
+✔ purrr     1.0.1     
+── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
+✖ dplyr::filter() masks stats::filter()
+✖ dplyr::lag()    masks stats::lag()
+ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
+
+
+
+

A fancy report

+

Hello

+
+ + +
+ + +
+ + + + \ No newline at end of file From 4c1bb785594f4ad57f3d7ae4f9cfc5754bc9a47d Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 28 Apr 2023 12:00:04 -0400 Subject: [PATCH 2/9] Update .Rbuildignore --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index 090ce293..f64dee63 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -17,3 +17,4 @@ ^LICENSE\.md$ inst/examples/rsconnect ^vignettes$ +^scripts$ From 98808be0efa01cc28faa0640cc1f5297ab6f8f0f Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Mon, 1 May 2023 10:25:13 -0400 Subject: [PATCH 3/9] Create quarto-postprocess.R --- scripts/quarto-postprocess.R | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/quarto-postprocess.R diff --git a/scripts/quarto-postprocess.R b/scripts/quarto-postprocess.R new file mode 100644 index 00000000..befef3e5 --- /dev/null +++ b/scripts/quarto-postprocess.R @@ -0,0 +1,45 @@ +# Ensure that certain packages are available +blastula_pkg_available() +jsonlite_pkg_available() +rmarkdown_pkg_available() + +library(rmarkdown) +library(blastula) +library(jsonlite) + +# Testing with two different HTML renders from Quarto +quarto_render_html_file <- + system.file( + "quarto_example_documents/quarto-report-render.html", + package = "blastula" + ) + +quarto_render_html_file_2 <- + system.file( + "quarto_example_documents/quarto-report-render-02.html", + package = "blastula" + ) + +# Generate the fragment of HTML that only contains the emailable material +email_fragment <- get_html_email_fragment(quarto_render_html_file_2) + +# Render the email fragment .Rmd and generate a list object with the +# needed components for Connect +rendered_email_obj <- + render_connect_email( + input = write_blastula_email_input_file(email_fragment), + connect_footer = FALSE, + envir = parent.frame(), + quiet = TRUE, + output_options = list(), + render_options = list() + ) + +finalize_quarto_connect_json_file( + input_json_file = system.file( + "quarto_example_documents/connect-email.json", + package = "blastula" + ), + output_json_file = "finalized.json", + rendered_email_obj = rendered_email_obj +) From 5988b7bee3fc274b8aa8056f745223fa61727143 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Mon, 1 May 2023 10:25:21 -0400 Subject: [PATCH 4/9] Create utils-quarto_emailing.R --- R/utils-quarto_emailing.R | 143 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 R/utils-quarto_emailing.R diff --git a/R/utils-quarto_emailing.R b/R/utils-quarto_emailing.R new file mode 100644 index 00000000..d056dc67 --- /dev/null +++ b/R/utils-quarto_emailing.R @@ -0,0 +1,143 @@ +# This function, to be used externally by scripts, will determine if +# the blastula package is available in the user system +blastula_pkg_available <- function() { + if (!requireNamespace("blastula", quietly = TRUE)) { + stop( + "The `blastula` package is required for processing email ", + "from Quarto documents." + ) + } +} + +jsonlite_pkg_available <- function() { + if (!requireNamespace("jsonlite", quietly = TRUE)) { + stop( + "The `jsonlite` package is required for processing email ", + "from Quarto documents." + ) + } +} + +rmarkdown_pkg_available <- function() { + if (!requireNamespace("rmarkdown", quietly = TRUE)) { + stop( + "The `rmarkdown` package is required for processing email ", + "from Quarto documents." + ) + } +} + +# Combine `path` with `filename` and normalize the path +blastula_resource_filename <- function(path, filename) { + + if (is.null(path)) { + path <- "." + } + + as.character( + fs::path_expand( + fs::path_abs( + path = filename, + start = path + ) + ) + ) +} + +get_quarto_report_render_html_path <- function() { + system.file( + "quarto_example_documents/quarto-report-render.html", + package = "blastula" + ) +} + +# Gets the HTML elements from CSS selector values +get_html_elements <- function(html, selector) { + rvest::html_elements(html, css = selector) +} + +detect_quarto_connect_json_file <- function( + filename = "connect-email.json", + path = NULL +) { + + filename <- blastula_resource_filename(path = path, filename = filename) + + if (!file.exists(filename)) { + warning("The JSON file required for Connect emailing cannot be found.") + return(invisible()) + } +} + +get_html_email_fragment <- function( + file, + selector = "[class='email']" +) { + + html_file_lines <- readLines(con = file, warn = FALSE) + html_file <- paste(html_file_lines, collapse = "\n") + html_read <- xml2::read_html(html_file) + + html_email_fragment <- + get_html_elements( + html = html_read, + selector = selector + ) + + html_email_fragment <- as.character(xml2::xml_children(html_email_fragment)) + html_email_fragment <- paste(html_email_fragment, collapse = "\n") + + html_email_fragment +} + +write_blastula_email_input_file <- function(html_fragment) { + + output_file <- tempfile(pattern = "email", fileext = ".Rmd") + + writeLines( + text = c( + "---", + "output: blastula::blastula_email", + "---", + "", + "", + html_fragment, + "" + ), + con = output_file + ) + + invisible(output_file) +} + +read_quarto_connect_json_file <- function(file) { + jsonlite::fromJSON(txt = file) +} + +write_quarto_connect_json_file <- function(obj, path) { + jsonlite::write_json(obj, path) +} + +finalize_quarto_connect_json_file <- function( + input_json_file, + output_json_file = NULL, + rendered_email_obj +) { + + connect_email_obj <- read_quarto_connect_json_file(file = input_json_file) + + connect_email_obj <- + c( + connect_email_obj, + list( + rsc_email_body_html = rendered_email_obj[["html_str"]], + rsc_email_images = rendered_email_obj[["images"]] + ) + ) + + if (is.null(output_json_file)) { + output_json_file <- input_json_file + } + + write_quarto_connect_json_file(connect_email_obj, path = output_json_file) +} From e1f5d9caca963e858dee04ba947bd699b6005ea0 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Mon, 1 May 2023 10:25:28 -0400 Subject: [PATCH 5/9] Create connect-email.json --- inst/quarto_example_documents/connect-email.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 inst/quarto_example_documents/connect-email.json diff --git a/inst/quarto_example_documents/connect-email.json b/inst/quarto_example_documents/connect-email.json new file mode 100644 index 00000000..fe1af5b5 --- /dev/null +++ b/inst/quarto_example_documents/connect-email.json @@ -0,0 +1 @@ +{"rsc_email_subject":"This is a subject.","rsc_email_attachments":["attach1.txt","attach2.txt"],"rsc_email_suppress_report_attachment":true,"rsc_email_suppress_scheduled":false} \ No newline at end of file From 759647f52fb9d73a761cd2f32bcaaf5139b8d5b1 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Mon, 1 May 2023 10:25:32 -0400 Subject: [PATCH 6/9] Create quarto-report-render-02.html --- .../quarto-report-render-02.html | 3330 +++++++++++++++++ 1 file changed, 3330 insertions(+) create mode 100644 inst/quarto_example_documents/quarto-report-render-02.html diff --git a/inst/quarto_example_documents/quarto-report-render-02.html b/inst/quarto_example_documents/quarto-report-render-02.html new file mode 100644 index 00000000..0a139bc0 --- /dev/null +++ b/inst/quarto_example_documents/quarto-report-render-02.html @@ -0,0 +1,3330 @@ + + + + + + + + + +report + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+
library(tidyverse)
+
+
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
+✔ dplyr     1.1.1     ✔ readr     2.1.4
+✔ forcats   1.0.0     ✔ stringr   1.5.0
+✔ ggplot2   3.4.1     ✔ tibble    3.2.1
+✔ lubridate 1.9.2     ✔ tidyr     1.3.0
+✔ purrr     1.0.1     
+── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
+✖ dplyr::filter() masks stats::filter()
+✖ dplyr::lag()    masks stats::lag()
+ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
+
+
+
+

A fancy report

+

Hello

+ +
+ +
+ + +
+ + + + \ No newline at end of file From fd292ec56a91d51a372c7dae0b05106f276a064c Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Mon, 1 May 2023 17:52:17 -0400 Subject: [PATCH 7/9] Update DESCRIPTION --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 9482b287..5afc7b31 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,6 +37,7 @@ Imports: mime (>= 0.6), rlang (>= 0.4.1), rmarkdown, + rvest (>= 1.0.3), stringr (>= 1.4.0), uuid (>= 0.1-2) Suggests: From e05c1a5c8a6f574664ad424f25298747e43bd172 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Tue, 2 May 2023 15:45:44 -0400 Subject: [PATCH 8/9] Delete cran-comments.md --- cran-comments.md | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 cran-comments.md diff --git a/cran-comments.md b/cran-comments.md deleted file mode 100644 index 40afbd70..00000000 --- a/cran-comments.md +++ /dev/null @@ -1,14 +0,0 @@ -## Test environments -* local OS X install, R 3.4.0 -* ubuntu 12.04 (on travis-ci), R 3.4.0 -* win-builder (devel and release) - -## R CMD check results - -0 errors | 0 warnings | 0 notes - -* This is a new release. - -## Reverse dependencies - -This is a new release, so there are no reverse dependencies. From ffc541db137e37d26e043b03d86a5212c1c73054 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Thu, 4 May 2023 15:58:20 -0400 Subject: [PATCH 9/9] Update quarto-postprocess.R --- scripts/quarto-postprocess.R | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/scripts/quarto-postprocess.R b/scripts/quarto-postprocess.R index befef3e5..f54d25e3 100644 --- a/scripts/quarto-postprocess.R +++ b/scripts/quarto-postprocess.R @@ -7,21 +7,22 @@ library(rmarkdown) library(blastula) library(jsonlite) -# Testing with two different HTML renders from Quarto -quarto_render_html_file <- - system.file( - "quarto_example_documents/quarto-report-render.html", - package = "blastula" - ) +# Get the filename for the rendered-by-Quarto HTML +html_file <- list.files(path = ".", pattern = ".*\\.html")[1] + +# Get the filename for the rendered-by-Quarto JSON +json_file <- list.files(path = ".", pattern = ".*\\.json")[1] + +# Stop if any of `html_file` or `json_file` are of zero length +if (length(html_file) < 1 || length(html_file) < 1) { + stop("There is no HTML or JSON file for which to generate a Connect email.") +} + +# Stop if the JSON file doesn't contain identifying text -quarto_render_html_file_2 <- - system.file( - "quarto_example_documents/quarto-report-render-02.html", - package = "blastula" - ) # Generate the fragment of HTML that only contains the emailable material -email_fragment <- get_html_email_fragment(quarto_render_html_file_2) +email_fragment <- get_html_email_fragment(file = html_file) # Render the email fragment .Rmd and generate a list object with the # needed components for Connect @@ -36,10 +37,7 @@ rendered_email_obj <- ) finalize_quarto_connect_json_file( - input_json_file = system.file( - "quarto_example_documents/connect-email.json", - package = "blastula" - ), - output_json_file = "finalized.json", + input_json_file = json_file, + output_json_file = json_file, rendered_email_obj = rendered_email_obj )