From cad160494deca59096d6c2c4c626e878d86b40d3 Mon Sep 17 00:00:00 2001 From: Dawid Kaledkowski Date: Wed, 4 Jun 2025 06:16:25 +0200 Subject: [PATCH 1/2] remove code_output --- NAMESPACE | 1 - R/doc.R | 17 ----------------- man/{code_output.Rd => code_chunk.Rd} | 12 ------------ tests/testthat/test-doc.R | 18 ++++++------------ 4 files changed, 6 insertions(+), 42 deletions(-) rename man/{code_output.Rd => code_chunk.Rd} (69%) diff --git a/NAMESPACE b/NAMESPACE index 1c22ad5af..ef7bc3b4e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,7 +41,6 @@ export(add_card_button_ui) export(as.teal_report) export(as_yaml_auto) export(code_chunk) -export(code_output) export(doc) export(download_report_button_srv) export(download_report_button_ui) diff --git a/R/doc.R b/R/doc.R index 4b248129f..8bbc7b6c1 100644 --- a/R/doc.R +++ b/R/doc.R @@ -185,7 +185,6 @@ edit_doc <- function(x, modify = NULL, append = NULL, after = length(x)) { #' class(my_chunk) #' attributes(my_chunk)$param #' @export -#' @rdname code_output code_chunk <- function(code, ...) { checkmate::assert_character(code) params <- list(...) @@ -196,22 +195,6 @@ code_chunk <- function(code, ...) { ) } -#' Format R code as a simple Markdown code block string -#' -#' This function takes a character string of R code and wraps it in -#' Markdown's triple backticks for code blocks. -#' -#' @param code A character string containing the R code. -#' @return A character string representing a simple Markdown code block. -#' @seealso [code_chunk()] for creating structured code chunk objects with options. -#' @examples -#' code_output("y <- rnorm(5)") -#' @export -#' @rdname code_output -code_output <- function(code) { - sprintf("```\n%s\n```", code) -} - #' @title Keep Objects In Report #' @description Utility function to change behavior of `doc` elements to be #' kept (`keep = TRUE`) or discarded (`keep = FALSE`) from the final `.Rmd` file containing the downloaded report. diff --git a/man/code_output.Rd b/man/code_chunk.Rd similarity index 69% rename from man/code_output.Rd rename to man/code_chunk.Rd index 35f153b6b..42fb8d904 100644 --- a/man/code_output.Rd +++ b/man/code_chunk.Rd @@ -2,12 +2,9 @@ % Please edit documentation in R/doc.R \name{code_chunk} \alias{code_chunk} -\alias{code_output} \title{Generate an R Markdown code chunk} \usage{ code_chunk(code, ...) - -code_output(code) } \arguments{ \item{code}{A character string containing the R code.} @@ -16,23 +13,14 @@ code_output(code) } \value{ An object of class \code{code_chunk}. - -A character string representing a simple Markdown code block. } \description{ This function creates a \code{code_chunk} object, which represents an R Markdown code chunk. It stores the R code and any specified chunk options (e.g., \code{echo}, \code{eval}). These objects are typically processed later to generate the final R Markdown text. - -This function takes a character string of R code and wraps it in -Markdown's triple backticks for code blocks. } \examples{ my_chunk <- code_chunk("x <- 1:10", echo = TRUE, message = FALSE) class(my_chunk) attributes(my_chunk)$param -code_output("y <- rnorm(5)") -} -\seealso{ -\code{\link[=code_chunk]{code_chunk()}} for creating structured code chunk objects with options. } diff --git a/tests/testthat/test-doc.R b/tests/testthat/test-doc.R index cbc8c85d9..7789384ae 100644 --- a/tests/testthat/test-doc.R +++ b/tests/testthat/test-doc.R @@ -15,35 +15,35 @@ testthat::test_that("doc creates a doc with initial elements", { testthat::describe("c.doc combines with", { doc_base <- doc("a", "b") - it("character element and retains class", { + testthat::it("character element and retains class", { doc_result <- c(doc_base, "c") testthat::expect_s3_class(doc_result, "doc") testthat::expect_length(doc_result, 3) testthat::expect_equal(doc_result[[3]], "c") }) - it("multiple character elements and retains class", { + testthat::it("multiple character elements and retains class", { doc_result <- c(doc_base, "c", list("d")) testthat::expect_s3_class(doc_result, "doc") testthat::expect_length(doc_result, 4) testthat::expect_equal(doc_result[[3]], "c") }) - it("multiple character elements and retains class", { + testthat::it("multiple character elements and retains class", { doc_result <- c(doc_base, "c", list("d", "e")) testthat::expect_s3_class(doc_result, "doc") testthat::expect_length(doc_result, 4) testthat::expect_equal(doc_result[[4]], list("d", "e")) }) - it("doc with multiple elements and retains class", { + testthat::it("doc with multiple elements and retains class", { doc_result <- c(doc_base, doc("c", "d")) testthat::expect_s3_class(doc_result, "doc") testthat::expect_length(doc_result, 4) testthat::expect_equal(doc_result[[3]], "c") # Assuming it unnests the doc }) - it("with single ggplot2 element and retains class", { + testthat::it("with single ggplot2 element and retains class", { plot <- ggplot2::ggplot(mtcars, ggplot2::aes(x = wt, y = mpg)) + ggplot2::geom_point() doc_result <- c(doc_base, plot) @@ -52,7 +52,7 @@ testthat::describe("c.doc combines with", { testthat::expect_identical(doc_result[[3]], plot) }) - it("ggplot2 section and retains class", { + testthat::it("ggplot2 section and retains class", { plot <- ggplot2::ggplot(mtcars, ggplot2::aes(x = wt, y = mpg)) + ggplot2::geom_point() doc_result <- c(doc_base, doc("# Plot", plot)) @@ -126,12 +126,6 @@ testthat::test_that("code_chunk creates a code_chunk object with params", { testthat::expect_equal(attributes(chunk)$params, list(echo = FALSE, eval = TRUE)) }) -testthat::test_that("code_output formats code as markdown string", { - output <- code_output("x <- 1") - testthat::expect_type(output, "character") - testthat::expect_equal(output, "```\nx <- 1\n```") -}) - testthat::test_that("keep_in_report sets the 'keep' attribute", { obj1 <- "some text" kept_obj1 <- keep_in_report(obj1, TRUE) From 475e1ba83317588cac6a01f2feb9ffd54eff02be Mon Sep 17 00:00:00 2001 From: Dawid Kaledkowski Date: Wed, 4 Jun 2025 14:07:01 +0200 Subject: [PATCH 2/2] @averissimo --- tests/testthat/test-doc.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-doc.R b/tests/testthat/test-doc.R index 7789384ae..14aa396c6 100644 --- a/tests/testthat/test-doc.R +++ b/tests/testthat/test-doc.R @@ -15,35 +15,35 @@ testthat::test_that("doc creates a doc with initial elements", { testthat::describe("c.doc combines with", { doc_base <- doc("a", "b") - testthat::it("character element and retains class", { + it("character element and retains class", { doc_result <- c(doc_base, "c") testthat::expect_s3_class(doc_result, "doc") testthat::expect_length(doc_result, 3) testthat::expect_equal(doc_result[[3]], "c") }) - testthat::it("multiple character elements and retains class", { + it("multiple character elements and retains class", { doc_result <- c(doc_base, "c", list("d")) testthat::expect_s3_class(doc_result, "doc") testthat::expect_length(doc_result, 4) testthat::expect_equal(doc_result[[3]], "c") }) - testthat::it("multiple character elements and retains class", { + it("multiple character elements and retains class", { doc_result <- c(doc_base, "c", list("d", "e")) testthat::expect_s3_class(doc_result, "doc") testthat::expect_length(doc_result, 4) testthat::expect_equal(doc_result[[4]], list("d", "e")) }) - testthat::it("doc with multiple elements and retains class", { + it("doc with multiple elements and retains class", { doc_result <- c(doc_base, doc("c", "d")) testthat::expect_s3_class(doc_result, "doc") testthat::expect_length(doc_result, 4) testthat::expect_equal(doc_result[[3]], "c") # Assuming it unnests the doc }) - testthat::it("with single ggplot2 element and retains class", { + it("with single ggplot2 element and retains class", { plot <- ggplot2::ggplot(mtcars, ggplot2::aes(x = wt, y = mpg)) + ggplot2::geom_point() doc_result <- c(doc_base, plot) @@ -52,7 +52,7 @@ testthat::describe("c.doc combines with", { testthat::expect_identical(doc_result[[3]], plot) }) - testthat::it("ggplot2 section and retains class", { + it("ggplot2 section and retains class", { plot <- ggplot2::ggplot(mtcars, ggplot2::aes(x = wt, y = mpg)) + ggplot2::geom_point() doc_result <- c(doc_base, doc("# Plot", plot))