From 4bfdc729342e3daa043918f5af55481ccf9c2289 Mon Sep 17 00:00:00 2001 From: yohann Date: Fri, 27 Sep 2024 10:09:06 +0200 Subject: [PATCH 1/2] feat: Add development chunk in fusen templates --- inst/flat-template-additional.Rmd | 4 ++++ inst/flat-template-full.Rmd | 18 +++++++++++++----- inst/flat-template-minimal_package.Rmd | 4 ++++ inst/flat-template-teaching.Rmd | 7 ++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/inst/flat-template-additional.Rmd b/inst/flat-template-additional.Rmd index 244dcab9..2885b84c 100644 --- a/inst/flat-template-additional.Rmd +++ b/inst/flat-template-additional.Rmd @@ -16,6 +16,10 @@ pkgload::load_all(export_all = FALSE) # my_fun +```{r development-my_fun} +# Prepare the code of your function here +``` + ```{r function-my_fun} #' my_fun Title #' diff --git a/inst/flat-template-full.Rmd b/inst/flat-template-full.Rmd index 0dd65ff3..987c3c06 100644 --- a/inst/flat-template-full.Rmd +++ b/inst/flat-template-full.Rmd @@ -63,6 +63,10 @@ After inflating the template - This function code will automatically be added in a new file in the "R/" directory --> +```{r development-function} +# Prepare the code of your function here +``` + ```{r function} #' My median #' @@ -75,7 +79,9 @@ After inflating the template #' #' @examples my_median <- function(x, na.rm = TRUE) { - if (!is.numeric(x)) {stop("x should be numeric")} + if (!is.numeric(x)) { + stop("x should be numeric") + } stats::median(x, na.rm = na.rm) } ``` @@ -101,7 +107,7 @@ my_median(1:12) datafile <- system.file("nyc_squirrels_sample.csv", package = "") nyc_squirrels <- read.csv(datafile, encoding = "UTF-8") # Apply my function -my_median(nyc_squirrels[,"hectare_squirrel_number"]) +my_median(nyc_squirrels[, "hectare_squirrel_number"]) ``` +```{r development-add_one} +# Prepare the code of your function here +``` + ```{r function-add_one} #' Add one to any value #' From 4dbdb01c382fc67cbfb87c77e7dcc7deb63a8505 Mon Sep 17 00:00:00 2001 From: yohann Date: Fri, 27 Sep 2024 08:40:05 +0000 Subject: [PATCH 2/2] fix: fixing tests to account for extra dev chunk in fusen templates --- dev/flat_create_flat.Rmd | 16 ++++++++-------- tests/testthat/test-add_flat_template.R | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/dev/flat_create_flat.Rmd b/dev/flat_create_flat.Rmd index 7f81a326..1a14af1c 100644 --- a/dev/flat_create_flat.Rmd +++ b/dev/flat_create_flat.Rmd @@ -665,9 +665,9 @@ test_that("Other flat_name works", { ) expect_true(file.exists(file.path(dummypackage, "dev/flat_hello.Rmd"))) hello_flat <- readLines(dev_file_path) - # 9 times hello for function name + # 10 times hello for function name # 2 times hello in flat_hello.Rmd - expect_equal(length(grep("hello", hello_flat)), 9 + 2) + expect_equal(length(grep("hello", hello_flat)), 10 + 2) expect_equal(length(grep("flat_hello[.]Rmd", hello_flat)), 2) # Template minimal used with "minpkg", same name, flat changes name @@ -683,9 +683,9 @@ test_that("Other flat_name works", { flat_file <- file.path(dummypackage, "dev/flat_hello_2.Rmd") expect_true(file.exists(flat_file)) hello_flat <- readLines(flat_file) - # 9 times hello for function name + # 10 times hello for function name # 2 times hello in flat_hello_2.Rmd - expect_equal(length(grep("hello", hello_flat)), 9 + 2) + expect_equal(length(grep("hello", hello_flat)), 10 + 2) expect_equal(length(grep("flat_hello_2[.]Rmd", hello_flat)), 2) # Try inflate to see if files get hello name @@ -735,11 +735,11 @@ test_that("Other dev_dir works", { expect_true(file.exists(file.path(dummypackage, "devdir/flat_hello.Rmd"))) hello_flat <- readLines(dev_file_path) - # 9 times hello for function name + # 10 times hello for function name # 2 times hello in flat_hello.Rmd # 1 time devdir/flat_hello.Rmd # O time dev/flat_hello.Rmd - expect_equal(length(grep("hello", hello_flat)), 9 + 2) + expect_equal(length(grep("hello", hello_flat)), 10 + 2) expect_equal(length(grep("flat_hello[.]Rmd", hello_flat)), 2) expect_equal(length(grep("devdir/flat_hello[.]Rmd", hello_flat)), 1) expect_equal(length(grep("dev/flat_hello[.]Rmd", hello_flat)), 0) @@ -833,8 +833,8 @@ test_that("add_flat_template allows bad flat_name for function name with add", { ))) dev_lines <- readLines(flat_file) - # title x 1, function x 3, example x 2, tests x 3 - expect_equal(length(grep("bad_for_function_but_ok2", dev_lines)), 9) + # title x 1, development x 1, function x 3, example x 2, tests x 3 + expect_equal(length(grep("bad_for_function_but_ok2", dev_lines)), 10) }) unlink(dummypackage, recursive = TRUE) ``` diff --git a/tests/testthat/test-add_flat_template.R b/tests/testthat/test-add_flat_template.R index 62010de5..9c333d7b 100644 --- a/tests/testthat/test-add_flat_template.R +++ b/tests/testthat/test-add_flat_template.R @@ -370,9 +370,9 @@ test_that("Other flat_name works", { ) expect_true(file.exists(file.path(dummypackage, "dev/flat_hello.Rmd"))) hello_flat <- readLines(dev_file_path) - # 9 times hello for function name + # 10 times hello for function name # 2 times hello in flat_hello.Rmd - expect_equal(length(grep("hello", hello_flat)), 9 + 2) + expect_equal(length(grep("hello", hello_flat)), 10 + 2) expect_equal(length(grep("flat_hello[.]Rmd", hello_flat)), 2) # Template minimal used with "minpkg", same name, flat changes name @@ -388,9 +388,9 @@ test_that("Other flat_name works", { flat_file <- file.path(dummypackage, "dev/flat_hello_2.Rmd") expect_true(file.exists(flat_file)) hello_flat <- readLines(flat_file) - # 9 times hello for function name + # 10 times hello for function name # 2 times hello in flat_hello_2.Rmd - expect_equal(length(grep("hello", hello_flat)), 9 + 2) + expect_equal(length(grep("hello", hello_flat)), 10 + 2) expect_equal(length(grep("flat_hello_2[.]Rmd", hello_flat)), 2) # Try inflate to see if files get hello name @@ -440,11 +440,11 @@ test_that("Other dev_dir works", { expect_true(file.exists(file.path(dummypackage, "devdir/flat_hello.Rmd"))) hello_flat <- readLines(dev_file_path) - # 9 times hello for function name + # 10 times hello for function name # 2 times hello in flat_hello.Rmd # 1 time devdir/flat_hello.Rmd # O time dev/flat_hello.Rmd - expect_equal(length(grep("hello", hello_flat)), 9 + 2) + expect_equal(length(grep("hello", hello_flat)), 10 + 2) expect_equal(length(grep("flat_hello[.]Rmd", hello_flat)), 2) expect_equal(length(grep("devdir/flat_hello[.]Rmd", hello_flat)), 1) expect_equal(length(grep("dev/flat_hello[.]Rmd", hello_flat)), 0) @@ -538,8 +538,8 @@ test_that("add_flat_template allows bad flat_name for function name with add", { ))) dev_lines <- readLines(flat_file) - # title x 1, function x 3, example x 2, tests x 3 - expect_equal(length(grep("bad_for_function_but_ok2", dev_lines)), 9) + # title x 1, development x 1, function x 3, example x 2, tests x 3 + expect_equal(length(grep("bad_for_function_but_ok2", dev_lines)), 10) }) unlink(dummypackage, recursive = TRUE)