From 8b49fae3fd72e073c667b12e2988151c68007fce Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Tue, 4 Jun 2024 09:08:35 +0200 Subject: [PATCH 01/19] feat(wip): Setting sepuku #257 --- dev/flat_sepuku.Rmd | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dev/flat_sepuku.Rmd diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd new file mode 100644 index 00000000..c654a6fb --- /dev/null +++ b/dev/flat_sepuku.Rmd @@ -0,0 +1,66 @@ +--- +title: "flat_sepuku.Rmd empty" +output: html_document +editor_options: + chunk_output_type: console +--- + +```{r development, include=FALSE} +library(testthat) +``` + +```{r development-load} +# Load already included functions if relevant +pkgload::load_all(export_all = FALSE) +``` + +# sepuku + +```{r function-sepuku} +#' sepuku Title +#' +#' @return 1 +#' @export +#' +#' @examples +sepuku <- function( + pkg = ".") { + # Check if the package has a dev folder + if (!dir.exists(file.path(pkg, "dev"))) { + stop("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") + } +} +``` + +```{r examples-sepuku} +sepuku() +``` + +```{r tests-sepuku} +dummypackage <- tempfile("sepuku") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +test_that("sepuku is a function", { + expect_true(inherits(sepuku, "function")) +}) + +usethis::with_project(dummypackage, { + browser() + # Add licence + usethis::use_mit_license("John Doe") + + #  Check for a dev folder + expect_error( + sepuku(), "No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?" + ) +}) +``` + + +```{r development-inflate, eval=FALSE} +# Run but keep eval=FALSE to avoid infinite loop +# Execute in the console directly +fusen::inflate(flat_file = "dev/flat_sepuku.Rmd", vignette_name = "Go further") +``` + From 987f77a9e7934d4a6b4694bca093bba8c04db18d Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Tue, 4 Jun 2024 09:22:16 +0200 Subject: [PATCH 02/19] feat(wip): sepuku logic for fusen configuration file #257 --- dev/flat_sepuku.Rmd | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index c654a6fb..3b16b8d4 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -25,9 +25,16 @@ pkgload::load_all(export_all = FALSE) #' @examples sepuku <- function( pkg = ".") { - # Check if the package has a dev folder if (!dir.exists(file.path(pkg, "dev"))) { - stop("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") + cli::cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") + } + + config_file <- getOption("fusen.config_file", default = "dev/config_fusen.yaml") + + if (!file.exists(config_file)) { + cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as files starting with 'flat' in the dev/ folder.") + } else { + cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as those starting with 'flat' in the dev/ folder.") } } ``` @@ -50,10 +57,36 @@ usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") - #  Check for a dev folder - expect_error( - sepuku(), "No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?" - ) + test_that("sepuku checks that a dev/ folder exists", { + #  Check for a dev folder + expect_error( + sepuku(), "No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?" + ) + }) + + dev_file <- suppressMessages(add_minimal_package(overwrite = TRUE, open = FALSE)) + + test_that("sepuku checks whether a fusen config file exists or not", { + expect_message( + sepuku(), "No fusen configuration file found. The flat files to be deleted will be identified as files starting with 'flat' in the dev/ folder." + ) + + # To add the config file a first inflate is needed + flat_file <- dev_file[grepl("flat_", dev_file)] + + suppressMessages( + inflate( + pkg = dummypackage, flat_file = flat_file, + vignette_name = "Get started", check = FALSE, + open_vignette = FALSE, document = TRUE, + overwrite = "yes" + ) + ) + + expect_message( + sepuku(), "A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as those starting with 'flat' in the dev/ folder." + ) + }) }) ``` From 2db9c35e3a2c267a636dc59bf4e70f1f454e4aed Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Tue, 4 Jun 2024 09:48:59 +0200 Subject: [PATCH 03/19] feat(wip): initiation sepuku utils #257 --- dev/flat_sepuku-utils.Rmd | 48 ++++++++++++++++++++++++++++++++++++++ dev/flat_sepuku.Rmd | 49 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 dev/flat_sepuku-utils.Rmd diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd new file mode 100644 index 00000000..a391071a --- /dev/null +++ b/dev/flat_sepuku-utils.Rmd @@ -0,0 +1,48 @@ +--- +title: "flat_sepuku-utils.Rmd empty" +output: html_document +editor_options: + chunk_output_type: console +--- + +```{r development, include=FALSE} +library(testthat) +``` + +```{r development-load} +# Load already included functions if relevant +pkgload::load_all(export_all = FALSE) +``` + +# list_flat_files + +```{r function-list_flat_files} +#' Title +#' +#' Description +#' +#' @return +#' +#' @export +list_flat_files <- function() { + +} +``` + +```{r example-list_flat_files} +list_flat_files() +``` + +```{r tests-list_flat_files} +test_that("list_flat_files works", { + expect_true(inherits(list_flat_files, "function")) +}) +``` + + +```{r development-inflate, eval=FALSE} +# Run but keep eval=FALSE to avoid infinite loop +# Execute in the console directly +fusen::inflate(flat_file = "dev/flat_sepuku-utils.Rmd", vignette_name = "Go further") +``` + diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index 3b16b8d4..ba85c2d2 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -44,7 +44,7 @@ sepuku() ``` ```{r tests-sepuku} -dummypackage <- tempfile("sepuku") +dummypackage <- tempfile("sepuku.first") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) @@ -53,7 +53,6 @@ test_that("sepuku is a function", { }) usethis::with_project(dummypackage, { - browser() # Add licence usethis::use_mit_license("John Doe") @@ -88,8 +87,54 @@ usethis::with_project(dummypackage, { ) }) }) + +unlink(dummypackage, recursive = TRUE) ``` +```{r tests-sepuku} +dummypackage <- tempfile("sepuku.second") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + browser() + test_that("sepuku raises a message if no flat files have been found", { + #  Check for a dev folder + expect_error( + sepuku(), "No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?" + ) + }) + + dev_file <- suppressMessages(add_minimal_package(overwrite = TRUE, open = FALSE)) + + test_that("sepuku checks whether a fusen config file exists or not", { + expect_message( + sepuku(), "No fusen configuration file found. The flat files to be deleted will be identified as files starting with 'flat' in the dev/ folder." + ) + + # To add the config file a first inflate is needed + flat_file <- dev_file[grepl("flat_", dev_file)] + + suppressMessages( + inflate( + pkg = dummypackage, flat_file = flat_file, + vignette_name = "Get started", check = FALSE, + open_vignette = FALSE, document = TRUE, + overwrite = "yes" + ) + ) + + expect_message( + sepuku(), "A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as those starting with 'flat' in the dev/ folder." + ) + }) +}) + +unlink(dummypackage, recursive = TRUE) +``` ```{r development-inflate, eval=FALSE} # Run but keep eval=FALSE to avoid infinite loop From 3c3c3ec92c4bb7f9ebec44acf7a164f738e11a04 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Wed, 5 Jun 2024 09:32:44 +0200 Subject: [PATCH 04/19] feat(wip): A function to list flat files in fusen config file #258 #257 --- dev/flat_sepuku-utils.Rmd | 164 +++++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 2 deletions(-) diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index a391071a..6fbfb122 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -14,7 +14,114 @@ library(testthat) pkgload::load_all(export_all = FALSE) ``` -# list_flat_files + +# list_flat_files_in_config_file + +```{r function-list_flat_files_in_config_file} +#' @importFrom yaml read_yaml +#' @noRd +list_flat_files_in_config_file <- function( + config_file = getOption("fusen.config_file", + default = "dev/config_fusen.yaml" + )) { + if (!file.exists(config_file)) { + return("") + } else { + config_yml <- yaml::read_yaml(config_file) + return( + unlist( + lapply(config_yml, "[[", "path") + ) + ) + } +} +``` + +```{r tests-list_flat_files_in_config_file} +test_that("list_flat_files_in_config_file is a function", { + expect_true(inherits(list_flat_files_in_config_file, "function")) +}) + +dummypackage <- tempfile("listflatfiles.first") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) +flat_file1 <- add_minimal_package( + pkg = dummypackage, + overwrite = TRUE, + open = FALSE +) +flat_file1 <- flat_file1[grepl("flat_", flat_file1)] + + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("list_flat_files works when no fusen config file is present", { + identified_flat_files <- list_flat_files_in_config_file() + expect_true(!is.null(identified_flat_files)) + expect_equal(identified_flat_files, "") + }) +}) + +usethis::with_project(dummypackage, { + test_that("list_flat_files works for a fusen config file", { + flat_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "XXX_flat2.Rmd", + open = FALSE + ) + + inflate( + pkg = dummypackage, + flat_file = flat_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + inflate( + pkg = dummypackage, + flat_file = flat_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + identified_flat_files <- list_flat_files_in_config_file() + + expect_equal( + length(identified_flat_files), 2 + ) + + expect_true( + all( + identified_flat_files %in% c("dev/flat_minimal.Rmd", "dev/flat_xxx_flat2.Rmd") + ) + ) + + # Pas de config file et rien dans dev + + #  Pas de config file et un fichier dans dev + + #  Pas de config file et un fichier dans dev avec un nom qui ne commence pas par flat + + # Inflate les 2 : on a un config file + + #  Gérer les qmd + + # Deprecated un flat file + }) +}) +unlink(dummypackage, recursive = TRUE) +``` + + + # list_flat_files ```{r function-list_flat_files} #' Title @@ -34,12 +141,65 @@ list_flat_files() ``` ```{r tests-list_flat_files} -test_that("list_flat_files works", { +test_that("list_flat_files is a function", { expect_true(inherits(list_flat_files, "function")) }) + +dummypackage <- tempfile("listflatfiles.first") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("list_flat_files works for a fusen config file", { + browser() + + dev_file1 <- add_minimal_flat(pkg = dummypackage, flat_name = "flat1.Rmd", open = FALSE) + dev_file2 <- add_minimal_flat(pkg = dummypackage, flat_name = "XXX_flat2.Rmd", open = FALSE) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + config_yml_ref <- + yaml::read_yaml(getOption("fusen.config_file", default = "dev/config_fusen.yaml")) + }) + + # Pas de config file et rien dans dev + + #  Pas de config file et un fichier dans dev + + #  Pas de config file et un fichier dans dev avec un nom qui ne commence pas par flat + + # Inflate les 2 : on a un config file + + #  Gérer les qmd + + # Deprecated un flat file +}) ``` + + ```{r development-inflate, eval=FALSE} # Run but keep eval=FALSE to avoid infinite loop # Execute in the console directly From b7ae149d63062121171341190e5541ea3b8bdd2f Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Wed, 5 Jun 2024 10:06:19 +0200 Subject: [PATCH 05/19] feat(wip): List flat files in dev/, flat_history/ and in config fusen yml #257 #258 --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/sepuku_utils.R | 57 ++++++++ dev/config_fusen.yaml | 14 ++ dev/flat_sepuku-utils.Rmd | 214 +++++++++++++++++++++-------- man/sepuku_utils.Rd | 11 ++ tests/testthat/test-sepuku_utils.R | 205 +++++++++++++++++++++++++++ 7 files changed, 449 insertions(+), 55 deletions(-) create mode 100644 R/sepuku_utils.R create mode 100644 man/sepuku_utils.Rd create mode 100644 tests/testthat/test-sepuku_utils.R diff --git a/DESCRIPTION b/DESCRIPTION index 7b599d48..54e8379f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,7 +48,7 @@ Suggests: withr VignetteBuilder: knitr -Config/fusen/version: 0.6.0 +Config/fusen/version: 0.6.0.9000 Config/testthat/edition: 3 Config/testthat/parallel: false Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 7f8af919..d14b8148 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ export(inflate) export(inflate_all) export(inflate_all_no_check) export(init_share_on_github) +export(list_flat_files) export(load_flat_functions) export(register_all_to_config) export(rename_flat_file) diff --git a/R/sepuku_utils.R b/R/sepuku_utils.R new file mode 100644 index 00000000..5aeb8625 --- /dev/null +++ b/R/sepuku_utils.R @@ -0,0 +1,57 @@ +# WARNING - Generated by {fusen} from dev/flat_sepuku-utils.Rmd: do not edit by hand + +#' @importFrom yaml read_yaml +#' @noRd +#' @rdname sepuku_utils +list_flat_files_in_config_file <- function( + config_file = getOption("fusen.config_file", + default = "dev/config_fusen.yaml" + )) { + if (!file.exists(config_file)) { + return("") + } else { + config_yml <- yaml::read_yaml(config_file) + return( + unlist( + lapply(config_yml, "[[", "path") + ) + ) + } +} + +#' @noRd +#' @rdname sepuku_utils +list_flat_files_in_dev_folder <- function( + pkg = ".", + folder = "dev") { + files_identified <- + c( + list.files( + path = file.path(pkg, folder), + pattern = "flat_.*\\.Rmd", + full.names = FALSE + ), + list.files( + path = file.path(pkg, folder), + pattern = "flat_.*\\.qmd", + full.names = FALSE + ) + ) + + file.path( + folder, + files_identified + ) +} + +#' Title +#' +#' Description +#' +#' @return +#' +#' @export +#' @rdname sepuku_utils +list_flat_files <- function() { + +} diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index dd3d9cfe..8205944f 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -140,6 +140,20 @@ flat_register_config_file.Rmd: document: true overwrite: 'yes' clean: ask +flat_sepuku-utils.Rmd: + path: dev/flat_sepuku-utils.Rmd + state: active + R: R/sepuku_utils.R + tests: tests/testthat/test-sepuku_utils.R + vignettes: [] + inflate: + flat_file: dev/flat_sepuku-utils.Rmd + vignette_name: .na + open_vignette: false + check: false + document: true + overwrite: 'yes' + clean: ask keep: path: keep state: active diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index 6fbfb122..e825729a 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -20,6 +20,7 @@ pkgload::load_all(export_all = FALSE) ```{r function-list_flat_files_in_config_file} #' @importFrom yaml read_yaml #' @noRd +#' @rdname sepuku_utils list_flat_files_in_config_file <- function( config_file = getOption("fusen.config_file", default = "dev/config_fusen.yaml" @@ -103,98 +104,197 @@ usethis::with_project(dummypackage, { identified_flat_files %in% c("dev/flat_minimal.Rmd", "dev/flat_xxx_flat2.Rmd") ) ) - - # Pas de config file et rien dans dev - - #  Pas de config file et un fichier dans dev - - #  Pas de config file et un fichier dans dev avec un nom qui ne commence pas par flat - - # Inflate les 2 : on a un config file - - #  Gérer les qmd - - # Deprecated un flat file }) }) unlink(dummypackage, recursive = TRUE) ``` - # list_flat_files +# list_flat_files_in_dev_folder -```{r function-list_flat_files} -#' Title -#' -#' Description -#' -#' @return -#' -#' @export -list_flat_files <- function() { +```{r function-list_flat_files_in_dev_folder} +#' @noRd +#' @rdname sepuku_utils +list_flat_files_in_dev_folder <- function( + pkg = ".", + folder = "dev") { + files_identified <- + c( + list.files( + path = file.path(pkg, folder), + pattern = "flat_.*\\.Rmd", + full.names = FALSE + ), + list.files( + path = file.path(pkg, folder), + pattern = "flat_.*\\.qmd", + full.names = FALSE + ) + ) + file.path( + folder, + files_identified + ) } ``` +`` -```{r example-list_flat_files} -list_flat_files() -``` - -```{r tests-list_flat_files} -test_that("list_flat_files is a function", { - expect_true(inherits(list_flat_files, "function")) +```{r tests-list_flat_files_in_dev_folder} +test_that("list_flat_files_in_dev_folder is a function", { + expect_true(inherits(list_flat_files_in_dev_folder, "function")) }) -dummypackage <- tempfile("listflatfiles.first") +dummypackage <- tempfile("listflatfilesindev.first") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) +flat_file1 <- add_minimal_package( + pkg = dummypackage, + overwrite = TRUE, + open = FALSE +) +flat_file1 <- flat_file1[grepl("flat_", flat_file1)] + usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") - test_that("list_flat_files works for a fusen config file", { - browser() + test_that("list_flat_files_in_dev_folder works for rmd and qmd files in dev folder starting with flat", { + flat_file_with_bad_name <- "xxx_flat2.Rmd" + file.create(file.path(dummypackage, "dev", flat_file_with_bad_name)) - dev_file1 <- add_minimal_flat(pkg = dummypackage, flat_name = "flat1.Rmd", open = FALSE) - dev_file2 <- add_minimal_flat(pkg = dummypackage, flat_name = "XXX_flat2.Rmd", open = FALSE) + identified_flat_files <- list_flat_files_in_dev_folder() - inflate( - pkg = dummypackage, - flat_file = dev_file1, - vignette_name = "Get started", - check = FALSE, - open_vignette = FALSE, - document = TRUE, - overwrite = "yes" + expect_equal(identified_flat_files, "dev/flat_minimal.Rmd") + + qmd_file <- "flat_minimal.qmd" + + file.create(file.path(dummypackage, "dev", qmd_file)) + + identified_flat_files <- list_flat_files_in_dev_folder() + + expect_equal( + length(identified_flat_files), 2 ) + expect_true( + all( + identified_flat_files %in% c("dev/flat_minimal.Rmd", "dev/flat_minimal.qmd") + ) + ) + }) + + test_that("list_flat_files_in_dev_folder works for rmd and qmd files in flat_history folder starting with flat", { inflate( pkg = dummypackage, - flat_file = dev_file2, - vignette_name = "Get started 2", + flat_file = flat_file1, + vignette_name = NA, check = FALSE, open_vignette = FALSE, document = TRUE, overwrite = "yes" ) - config_yml_ref <- - yaml::read_yaml(getOption("fusen.config_file", default = "dev/config_fusen.yaml")) - }) + deprecate_flat_file( + flat_file = flat_file1 + ) - # Pas de config file et rien dans dev + identified_flat_files <- list_flat_files_in_dev_folder(folder = "dev/flat_history") - #  Pas de config file et un fichier dans dev + expect_equal(identified_flat_files, "dev/flat_history/flat_minimal.Rmd") - #  Pas de config file et un fichier dans dev avec un nom qui ne commence pas par flat + qmd_file <- "flat_minimal.qmd" - # Inflate les 2 : on a un config file + file.create(file.path(dummypackage, "dev/flat_history", qmd_file)) - #  Gérer les qmd + identified_flat_files <- list_flat_files_in_dev_folder(folder = "dev/flat_history") - # Deprecated un flat file + expect_equal( + length(identified_flat_files), 2 + ) + + expect_true( + all( + identified_flat_files %in% c("dev/flat_history/flat_minimal.Rmd", "dev/flat_history/flat_minimal.qmd") + ) + ) + }) }) +unlink(dummypackage, recursive = TRUE) +``` + + + # list_flat_files + +```{r function-list_flat_files} +#' Title +#' +#' Description +#' +#' @return +#' +#' @export +#' @rdname sepuku_utils +list_flat_files <- function() { + +} +``` + + +```{r tests-list_flat_files} +# test_that("list_flat_files is a function", { +# expect_true(inherits(list_flat_files, "function")) +# }) + +# dummypackage <- tempfile("listflatfiles.first") +# dir.create(dummypackage) +# fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +# usethis::with_project(dummypackage, { +# # Add licence +# usethis::use_mit_license("John Doe") + +# test_that("list_flat_files works for a fusen config file", { +# dev_file1 <- add_minimal_flat(pkg = dummypackage, flat_name = "flat1.Rmd", open = FALSE) +# dev_file2 <- add_minimal_flat(pkg = dummypackage, flat_name = "XXX_flat2.Rmd", open = FALSE) + +# inflate( +# pkg = dummypackage, +# flat_file = dev_file1, +# vignette_name = "Get started", +# check = FALSE, +# open_vignette = FALSE, +# document = TRUE, +# overwrite = "yes" +# ) + +# inflate( +# pkg = dummypackage, +# flat_file = dev_file2, +# vignette_name = "Get started 2", +# check = FALSE, +# open_vignette = FALSE, +# document = TRUE, +# overwrite = "yes" +# ) + +# config_yml_ref <- +# yaml::read_yaml(getOption("fusen.config_file", default = "dev/config_fusen.yaml")) +# }) + +# Pas de config file et rien dans dev + +#  Pas de config file et un fichier dans dev + +#  Pas de config file et un fichier dans dev avec un nom qui ne commence pas par flat + +# Inflate les 2 : on a un config file + +#  Gérer les qmd + +# Deprecated un flat file +# }) ``` @@ -203,6 +303,12 @@ usethis::with_project(dummypackage, { ```{r development-inflate, eval=FALSE} # Run but keep eval=FALSE to avoid infinite loop # Execute in the console directly -fusen::inflate(flat_file = "dev/flat_sepuku-utils.Rmd", vignette_name = "Go further") +fusen::inflate( + flat_file = "dev/flat_sepuku-utils.Rmd", + vignette_name = NA, + check = FALSE, + overwrite = TRUE, + open_vignette = FALSE +) ``` diff --git a/man/sepuku_utils.Rd b/man/sepuku_utils.Rd new file mode 100644 index 00000000..9cc985e4 --- /dev/null +++ b/man/sepuku_utils.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sepuku_utils.R +\name{list_flat_files} +\alias{list_flat_files} +\title{Title} +\usage{ +list_flat_files() +} +\description{ +Description +} diff --git a/tests/testthat/test-sepuku_utils.R b/tests/testthat/test-sepuku_utils.R new file mode 100644 index 00000000..7a016c02 --- /dev/null +++ b/tests/testthat/test-sepuku_utils.R @@ -0,0 +1,205 @@ +# WARNING - Generated by {fusen} from dev/flat_sepuku-utils.Rmd: do not edit by hand + +test_that("list_flat_files_in_config_file is a function", { + expect_true(inherits(list_flat_files_in_config_file, "function")) +}) + +dummypackage <- tempfile("listflatfiles.first") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) +flat_file1 <- add_minimal_package( + pkg = dummypackage, + overwrite = TRUE, + open = FALSE +) +flat_file1 <- flat_file1[grepl("flat_", flat_file1)] + + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("list_flat_files works when no fusen config file is present", { + identified_flat_files <- list_flat_files_in_config_file() + expect_true(!is.null(identified_flat_files)) + expect_equal(identified_flat_files, "") + }) +}) + +usethis::with_project(dummypackage, { + test_that("list_flat_files works for a fusen config file", { + flat_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "XXX_flat2.Rmd", + open = FALSE + ) + + inflate( + pkg = dummypackage, + flat_file = flat_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + inflate( + pkg = dummypackage, + flat_file = flat_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + identified_flat_files <- list_flat_files_in_config_file() + + expect_equal( + length(identified_flat_files), 2 + ) + + expect_true( + all( + identified_flat_files %in% c("dev/flat_minimal.Rmd", "dev/flat_xxx_flat2.Rmd") + ) + ) + }) +}) +unlink(dummypackage, recursive = TRUE) + +test_that("list_flat_files_in_dev_folder is a function", { + expect_true(inherits(list_flat_files_in_dev_folder, "function")) +}) + +dummypackage <- tempfile("listflatfilesindev.first") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) +flat_file1 <- add_minimal_package( + pkg = dummypackage, + overwrite = TRUE, + open = FALSE +) +flat_file1 <- flat_file1[grepl("flat_", flat_file1)] + + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("list_flat_files_in_dev_folder works for rmd and qmd files in dev folder starting with flat", { + flat_file_with_bad_name <- "xxx_flat2.Rmd" + file.create(file.path(dummypackage, "dev", flat_file_with_bad_name)) + + identified_flat_files <- list_flat_files_in_dev_folder() + + expect_equal(identified_flat_files, "dev/flat_minimal.Rmd") + + qmd_file <- "flat_minimal.qmd" + + file.create(file.path(dummypackage, "dev", qmd_file)) + + identified_flat_files <- list_flat_files_in_dev_folder() + + expect_equal( + length(identified_flat_files), 2 + ) + + expect_true( + all( + identified_flat_files %in% c("dev/flat_minimal.Rmd", "dev/flat_minimal.qmd") + ) + ) + }) + + test_that("list_flat_files_in_dev_folder works for rmd and qmd files in flat_history folder starting with flat", { + inflate( + pkg = dummypackage, + flat_file = flat_file1, + vignette_name = NA, + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + deprecate_flat_file( + flat_file = flat_file1 + ) + + identified_flat_files <- list_flat_files_in_dev_folder(folder = "dev/flat_history") + + expect_equal(identified_flat_files, "dev/flat_history/flat_minimal.Rmd") + + qmd_file <- "flat_minimal.qmd" + + file.create(file.path(dummypackage, "dev/flat_history", qmd_file)) + + identified_flat_files <- list_flat_files_in_dev_folder(folder = "dev/flat_history") + + expect_equal( + length(identified_flat_files), 2 + ) + + expect_true( + all( + identified_flat_files %in% c("dev/flat_history/flat_minimal.Rmd", "dev/flat_history/flat_minimal.qmd") + ) + ) + }) +}) +unlink(dummypackage, recursive = TRUE) + +# test_that("list_flat_files is a function", { +# expect_true(inherits(list_flat_files, "function")) +# }) + +# dummypackage <- tempfile("listflatfiles.first") +# dir.create(dummypackage) +# fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +# usethis::with_project(dummypackage, { +# # Add licence +# usethis::use_mit_license("John Doe") + +# test_that("list_flat_files works for a fusen config file", { +# dev_file1 <- add_minimal_flat(pkg = dummypackage, flat_name = "flat1.Rmd", open = FALSE) +# dev_file2 <- add_minimal_flat(pkg = dummypackage, flat_name = "XXX_flat2.Rmd", open = FALSE) + +# inflate( +# pkg = dummypackage, +# flat_file = dev_file1, +# vignette_name = "Get started", +# check = FALSE, +# open_vignette = FALSE, +# document = TRUE, +# overwrite = "yes" +# ) + +# inflate( +# pkg = dummypackage, +# flat_file = dev_file2, +# vignette_name = "Get started 2", +# check = FALSE, +# open_vignette = FALSE, +# document = TRUE, +# overwrite = "yes" +# ) + +# config_yml_ref <- +# yaml::read_yaml(getOption("fusen.config_file", default = "dev/config_fusen.yaml")) +# }) + +# Pas de config file et rien dans dev + +#  Pas de config file et un fichier dans dev + +#  Pas de config file et un fichier dans dev avec un nom qui ne commence pas par flat + +# Inflate les 2 : on a un config file + +#  Gérer les qmd + +# Deprecated un flat file +# }) From 2a61341b33d6d5623ffdd6a895601588ddbff8e1 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Wed, 5 Jun 2024 10:52:30 +0200 Subject: [PATCH 06/19] feat: List all flat files in a pkg #258 #257 --- DESCRIPTION | 2 +- R/sepuku_utils.R | 18 ++- dev/config_fusen.yaml | 1 - dev/flat_sepuku-utils.Rmd | 184 +++++++++++++++++++---------- man/sepuku_utils.Rd | 12 +- tests/testthat/test-sepuku_utils.R | 138 +++++++++++++++------- 6 files changed, 239 insertions(+), 116 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 54e8379f..f5b27ca0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,7 +48,7 @@ Suggests: withr VignetteBuilder: knitr -Config/fusen/version: 0.6.0.9000 +Config/fusen/version: 0.5.2 Config/testthat/edition: 3 Config/testthat/parallel: false Encoding: UTF-8 diff --git a/R/sepuku_utils.R b/R/sepuku_utils.R index 5aeb8625..5f781600 100644 --- a/R/sepuku_utils.R +++ b/R/sepuku_utils.R @@ -8,7 +8,7 @@ list_flat_files_in_config_file <- function( default = "dev/config_fusen.yaml" )) { if (!file.exists(config_file)) { - return("") + return(character(0)) } else { config_yml <- yaml::read_yaml(config_file) return( @@ -44,14 +44,20 @@ list_flat_files_in_dev_folder <- function( ) } -#' Title +#' List all flat files present in the package #' -#' Description +#' Search for flat files listed in fusen config file, and for rmd and qmd files starting with "flat_" in dev/ folder, and dev/flat_history folder #' -#' @return +#' @param pkg Path to package +#' @return a vector of flat files paths #' #' @export #' @rdname sepuku_utils -list_flat_files <- function() { - +list_flat_files <- function(pkg = ".") { + c( + list_flat_files_in_config_file(), + list_flat_files_in_dev_folder(folder = "dev"), + list_flat_files_in_dev_folder(folder = "dev/flat_history") + ) %>% + unique() } diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index 8205944f..28a33e43 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -153,7 +153,6 @@ flat_sepuku-utils.Rmd: check: false document: true overwrite: 'yes' - clean: ask keep: path: keep state: active diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index e825729a..78c72479 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -26,7 +26,7 @@ list_flat_files_in_config_file <- function( default = "dev/config_fusen.yaml" )) { if (!file.exists(config_file)) { - return("") + return(character(0)) } else { config_yml <- yaml::read_yaml(config_file) return( @@ -61,7 +61,7 @@ usethis::with_project(dummypackage, { test_that("list_flat_files works when no fusen config file is present", { identified_flat_files <- list_flat_files_in_config_file() expect_true(!is.null(identified_flat_files)) - expect_equal(identified_flat_files, "") + expect_equal(length(identified_flat_files), 0) }) }) @@ -101,7 +101,8 @@ usethis::with_project(dummypackage, { expect_true( all( - identified_flat_files %in% c("dev/flat_minimal.Rmd", "dev/flat_xxx_flat2.Rmd") + identified_flat_files %in% + c("dev/flat_minimal.Rmd", "dev/flat_xxx_flat2.Rmd") ) ) }) @@ -225,80 +226,137 @@ unlink(dummypackage, recursive = TRUE) ``` - # list_flat_files +# list_flat_files ```{r function-list_flat_files} -#' Title +#' List all flat files present in the package #' -#' Description +#' Search for flat files listed in fusen config file, and for rmd and qmd files starting with "flat_" in dev/ folder, and dev/flat_history folder #' -#' @return +#' @param pkg Path to package +#' @return a vector of flat files paths #' #' @export #' @rdname sepuku_utils -list_flat_files <- function() { - +list_flat_files <- function(pkg = ".") { + c( + list_flat_files_in_config_file(), + list_flat_files_in_dev_folder(folder = "dev"), + list_flat_files_in_dev_folder(folder = "dev/flat_history") + ) %>% + unique() } ``` ```{r tests-list_flat_files} -# test_that("list_flat_files is a function", { -# expect_true(inherits(list_flat_files, "function")) -# }) - -# dummypackage <- tempfile("listflatfiles.first") -# dir.create(dummypackage) -# fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) - -# usethis::with_project(dummypackage, { -# # Add licence -# usethis::use_mit_license("John Doe") - -# test_that("list_flat_files works for a fusen config file", { -# dev_file1 <- add_minimal_flat(pkg = dummypackage, flat_name = "flat1.Rmd", open = FALSE) -# dev_file2 <- add_minimal_flat(pkg = dummypackage, flat_name = "XXX_flat2.Rmd", open = FALSE) - -# inflate( -# pkg = dummypackage, -# flat_file = dev_file1, -# vignette_name = "Get started", -# check = FALSE, -# open_vignette = FALSE, -# document = TRUE, -# overwrite = "yes" -# ) - -# inflate( -# pkg = dummypackage, -# flat_file = dev_file2, -# vignette_name = "Get started 2", -# check = FALSE, -# open_vignette = FALSE, -# document = TRUE, -# overwrite = "yes" -# ) - -# config_yml_ref <- -# yaml::read_yaml(getOption("fusen.config_file", default = "dev/config_fusen.yaml")) -# }) - -# Pas de config file et rien dans dev - -#  Pas de config file et un fichier dans dev - -#  Pas de config file et un fichier dans dev avec un nom qui ne commence pas par flat - -# Inflate les 2 : on a un config file - -#  Gérer les qmd - -# Deprecated un flat file -# }) -``` - +test_that("list_flat_files is a function", { + expect_true(inherits(list_flat_files, "function")) +}) + +dummypackage <- tempfile("listflatfiles.first") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("list_flat_files works with an empty pkg", { + flat_files <- list_flat_files() + expect_equal(length(flat_files), 0) + }) + + test_that("list_flat_files works with flat files in dev but no config file", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + + file.create(file.path(dummypackage, "dev", "flat_1.qmd")) + file.create(file.path(dummypackage, "dev", "wrong_flat1.Rmd")) + file.create(file.path(dummypackage, "dev", "wrong_flat1.qmd")) + flat_files <- list_flat_files() + expect_equal( + length(flat_files), 2 + ) + + expect_true( + all( + flat_files %in% c("dev/flat_flat1.Rmd", "dev/flat_1.qmd") + ) + ) + }) + test_that("list_flat_files works with flat files in dev and a config file", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + flat_files <- list_flat_files() + expect_equal( + length(flat_files), 2 + ) + + expect_true( + all( + flat_files %in% c("dev/flat_flat1.Rmd", "dev/flat_1.qmd") + ) + ) + }) + + test_that("list_flat_files works with a deprecated flat file", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + deprecate_flat_file( + flat_file = dev_file1 + ) + + flat_files <- list_flat_files() + expect_equal( + length(flat_files), 2 + ) + + expect_true( + all( + flat_files %in% c("dev/flat_history/flat_flat1.Rmd", "dev/flat_1.qmd") + ) + ) + }) +}) +unlink(dummypackage, recursive = TRUE) +``` + ```{r development-inflate, eval=FALSE} # Run but keep eval=FALSE to avoid infinite loop diff --git a/man/sepuku_utils.Rd b/man/sepuku_utils.Rd index 9cc985e4..234ddeff 100644 --- a/man/sepuku_utils.Rd +++ b/man/sepuku_utils.Rd @@ -2,10 +2,16 @@ % Please edit documentation in R/sepuku_utils.R \name{list_flat_files} \alias{list_flat_files} -\title{Title} +\title{List all flat files present in the package} \usage{ -list_flat_files() +list_flat_files(pkg = ".") +} +\arguments{ +\item{pkg}{Path to package} +} +\value{ +a vector of flat files paths } \description{ -Description +Search for flat files listed in fusen config file, and for rmd and qmd files starting with "flat_" in dev/ folder, and dev/flat_history folder } diff --git a/tests/testthat/test-sepuku_utils.R b/tests/testthat/test-sepuku_utils.R index 7a016c02..608407a4 100644 --- a/tests/testthat/test-sepuku_utils.R +++ b/tests/testthat/test-sepuku_utils.R @@ -22,7 +22,7 @@ usethis::with_project(dummypackage, { test_that("list_flat_files works when no fusen config file is present", { identified_flat_files <- list_flat_files_in_config_file() expect_true(!is.null(identified_flat_files)) - expect_equal(identified_flat_files, "") + expect_equal(length(identified_flat_files), 0) }) }) @@ -62,7 +62,8 @@ usethis::with_project(dummypackage, { expect_true( all( - identified_flat_files %in% c("dev/flat_minimal.Rmd", "dev/flat_xxx_flat2.Rmd") + identified_flat_files %in% + c("dev/flat_minimal.Rmd", "dev/flat_xxx_flat2.Rmd") ) ) }) @@ -151,55 +152,108 @@ usethis::with_project(dummypackage, { }) unlink(dummypackage, recursive = TRUE) -# test_that("list_flat_files is a function", { -# expect_true(inherits(list_flat_files, "function")) -# }) +test_that("list_flat_files is a function", { + expect_true(inherits(list_flat_files, "function")) +}) + +dummypackage <- tempfile("listflatfiles.first") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("list_flat_files works with an empty pkg", { + flat_files <- list_flat_files() + expect_equal(length(flat_files), 0) + }) + + test_that("list_flat_files works with flat files in dev but no config file", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) -# dummypackage <- tempfile("listflatfiles.first") -# dir.create(dummypackage) -# fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + file.create(file.path(dummypackage, "dev", "flat_1.qmd")) + file.create(file.path(dummypackage, "dev", "wrong_flat1.Rmd")) + file.create(file.path(dummypackage, "dev", "wrong_flat1.qmd")) -# usethis::with_project(dummypackage, { -# # Add licence -# usethis::use_mit_license("John Doe") + flat_files <- list_flat_files() + expect_equal( + length(flat_files), 2 + ) -# test_that("list_flat_files works for a fusen config file", { -# dev_file1 <- add_minimal_flat(pkg = dummypackage, flat_name = "flat1.Rmd", open = FALSE) -# dev_file2 <- add_minimal_flat(pkg = dummypackage, flat_name = "XXX_flat2.Rmd", open = FALSE) + expect_true( + all( + flat_files %in% c("dev/flat_flat1.Rmd", "dev/flat_1.qmd") + ) + ) + }) -# inflate( -# pkg = dummypackage, -# flat_file = dev_file1, -# vignette_name = "Get started", -# check = FALSE, -# open_vignette = FALSE, -# document = TRUE, -# overwrite = "yes" -# ) + test_that("list_flat_files works with flat files in dev and a config file", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE + ) -# inflate( -# pkg = dummypackage, -# flat_file = dev_file2, -# vignette_name = "Get started 2", -# check = FALSE, -# open_vignette = FALSE, -# document = TRUE, -# overwrite = "yes" -# ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) -# config_yml_ref <- -# yaml::read_yaml(getOption("fusen.config_file", default = "dev/config_fusen.yaml")) -# }) + flat_files <- list_flat_files() + expect_equal( + length(flat_files), 2 + ) -# Pas de config file et rien dans dev + expect_true( + all( + flat_files %in% c("dev/flat_flat1.Rmd", "dev/flat_1.qmd") + ) + ) + }) -#  Pas de config file et un fichier dans dev + test_that("list_flat_files works with a deprecated flat file", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE + ) -#  Pas de config file et un fichier dans dev avec un nom qui ne commence pas par flat + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) -# Inflate les 2 : on a un config file + deprecate_flat_file( + flat_file = dev_file1 + ) -#  Gérer les qmd + flat_files <- list_flat_files() + expect_equal( + length(flat_files), 2 + ) -# Deprecated un flat file -# }) + expect_true( + all( + flat_files %in% c("dev/flat_history/flat_flat1.Rmd", "dev/flat_1.qmd") + ) + ) + }) +}) +unlink(dummypackage, recursive = TRUE) From df6a3b78552307557f292c60786c771abd0edc17 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Wed, 5 Jun 2024 11:28:13 +0200 Subject: [PATCH 07/19] feat(wip): find files with fusen tags #259 --- DESCRIPTION | 2 +- R/sepuku_utils.R | 60 +++++++++++++ dev/config_fusen.yaml | 1 + dev/flat_sepuku-utils.Rmd | 140 ++++++++++++++++++++++++++++- tests/testthat/test-sepuku_utils.R | 67 +++++++++++++- 5 files changed, 262 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f5b27ca0..54e8379f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,7 +48,7 @@ Suggests: withr VignetteBuilder: knitr -Config/fusen/version: 0.5.2 +Config/fusen/version: 0.6.0.9000 Config/testthat/edition: 3 Config/testthat/parallel: false Encoding: UTF-8 diff --git a/R/sepuku_utils.R b/R/sepuku_utils.R index 5f781600..75fa42c0 100644 --- a/R/sepuku_utils.R +++ b/R/sepuku_utils.R @@ -61,3 +61,63 @@ list_flat_files <- function(pkg = ".") { ) %>% unique() } + +#' @noRd +#' @rdname sepuku_utils +find_files_with_fusen_tags <- function(pkg = ".") { + R_files_to_parse <- + lapply( + c("R", "tests/testthat/"), + function(folder) { + list.files( + path = file.path(pkg, folder), + pattern = "*\\.R", + full.names = TRUE + ) + } + ) %>% + unlist() %>% + normalizePath() + + Rmd_files_to_parse <- lapply( + "vignettes", + function(folder) { + list.files( + path = file.path(pkg, folder), + pattern = "*\\.Rmd", + full.names = TRUE + ) + } + ) %>% + unlist() %>% + normalizePath() + + files_to_parse <- c(R_files_to_parse, Rmd_files_to_parse) + + if (length(files_to_parse) == 0) { + return(character(0)) + } + + fusen_tags <- tolower( + c("WARNING - Generated by", "Previously generated by", "WARNING - This vignette is generated by") + ) + files_with_fusen_tags <- + lapply( + files_to_parse, + function(file) { + if ( + length( + grep(paste(fusen_tags, collapse = "|"), tolower(readLines(file))) + ) > 0 + ) { + return(file) + } else { + return(character(0)) + } + } + ) %>% + unlist() %>% + unique() + + return(files_with_fusen_tags) +} diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index 28a33e43..8205944f 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -153,6 +153,7 @@ flat_sepuku-utils.Rmd: check: false document: true overwrite: 'yes' + clean: ask keep: path: keep state: active diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index 78c72479..09a27b5b 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -43,7 +43,7 @@ test_that("list_flat_files_in_config_file is a function", { expect_true(inherits(list_flat_files_in_config_file, "function")) }) -dummypackage <- tempfile("listflatfiles.first") +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) flat_file1 <- add_minimal_package( @@ -146,7 +146,7 @@ test_that("list_flat_files_in_dev_folder is a function", { expect_true(inherits(list_flat_files_in_dev_folder, "function")) }) -dummypackage <- tempfile("listflatfilesindev.first") +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) flat_file1 <- add_minimal_package( @@ -227,7 +227,10 @@ unlink(dummypackage, recursive = TRUE) # list_flat_files - + + + + ```{r function-list_flat_files} #' List all flat files present in the package #' @@ -254,7 +257,7 @@ test_that("list_flat_files is a function", { expect_true(inherits(list_flat_files, "function")) }) -dummypackage <- tempfile("listflatfiles.first") +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) @@ -358,6 +361,135 @@ unlink(dummypackage, recursive = TRUE) ``` +# find_files_with_fusen_tags + +```{r function-find_files_with_fusen_tags} +#' @noRd +#' @rdname sepuku_utils +find_files_with_fusen_tags <- function(pkg = ".") { + R_files_to_parse <- + lapply( + c("R", "tests/testthat/"), + function(folder) { + list.files( + path = file.path(pkg, folder), + pattern = "*\\.R", + full.names = TRUE + ) + } + ) %>% + unlist() %>% + normalizePath() + + Rmd_files_to_parse <- lapply( + "vignettes", + function(folder) { + list.files( + path = file.path(pkg, folder), + pattern = "*\\.Rmd", + full.names = TRUE + ) + } + ) %>% + unlist() %>% + normalizePath() + + files_to_parse <- c(R_files_to_parse, Rmd_files_to_parse) + + if (length(files_to_parse) == 0) { + return(character(0)) + } + + fusen_tags <- tolower( + c("WARNING - Generated by", "Previously generated by", "WARNING - This vignette is generated by") + ) + files_with_fusen_tags <- + lapply( + files_to_parse, + function(file) { + if ( + length( + grep(paste(fusen_tags, collapse = "|"), tolower(readLines(file))) + ) > 0 + ) { + return(file) + } else { + return(character(0)) + } + } + ) %>% + unlist() %>% + unique() + + return(files_with_fusen_tags) +} +``` + +```{r tests-find_files_with_fusen_tags} +test_that("find_files_with_fusen_tags is a function", { + expect_true(inherits(find_files_with_fusen_tags, "function")) +}) + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("find_files_with_fusen_tags works with an empty pkg", { + files_with_fusen_tags <- find_files_with_fusen_tags() + expect_equal(length(files_with_fusen_tags), 0) + }) + + test_that("find_files_with_fusen_tags identifies files created by fusen", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + files_with_fusen_tags <- find_files_with_fusen_tags() + expect_equal(length(files_with_fusen_tags), 3) + expect_true( + all( + files_with_fusen_tags %in% + file.path(dummypackage, c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R")) + ) + ) + }) + + test_that("find_files_with_fusen_tags do not identify files not created by fusen", { + usethis::use_r("donotfindme.R", open = FALSE) + usethis::use_test("donotfindme.R", open = FALSE) + file.create(file.path(dummypackage, "vignettes", "donotfindme.Rmd")) + + files_with_fusen_tags <- find_files_with_fusen_tags() + expect_equal(length(files_with_fusen_tags), 3) + expect_true( + all( + files_with_fusen_tags %in% + file.path(dummypackage, c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R")) + ) + ) + }) +}) +``` + + + ```{r development-inflate, eval=FALSE} # Run but keep eval=FALSE to avoid infinite loop # Execute in the console directly diff --git a/tests/testthat/test-sepuku_utils.R b/tests/testthat/test-sepuku_utils.R index 608407a4..a9401cfe 100644 --- a/tests/testthat/test-sepuku_utils.R +++ b/tests/testthat/test-sepuku_utils.R @@ -4,7 +4,7 @@ test_that("list_flat_files_in_config_file is a function", { expect_true(inherits(list_flat_files_in_config_file, "function")) }) -dummypackage <- tempfile("listflatfiles.first") +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) flat_file1 <- add_minimal_package( @@ -74,7 +74,7 @@ test_that("list_flat_files_in_dev_folder is a function", { expect_true(inherits(list_flat_files_in_dev_folder, "function")) }) -dummypackage <- tempfile("listflatfilesindev.first") +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) flat_file1 <- add_minimal_package( @@ -156,7 +156,7 @@ test_that("list_flat_files is a function", { expect_true(inherits(list_flat_files, "function")) }) -dummypackage <- tempfile("listflatfiles.first") +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) @@ -257,3 +257,64 @@ usethis::with_project(dummypackage, { }) }) unlink(dummypackage, recursive = TRUE) + +test_that("find_files_with_fusen_tags is a function", { + expect_true(inherits(find_files_with_fusen_tags, "function")) +}) + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("find_files_with_fusen_tags works with an empty pkg", { + files_with_fusen_tags <- find_files_with_fusen_tags() + expect_equal(length(files_with_fusen_tags), 0) + }) + + test_that("find_files_with_fusen_tags identifies files created by fusen", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + files_with_fusen_tags <- find_files_with_fusen_tags() + expect_equal(length(files_with_fusen_tags), 3) + expect_true( + all( + files_with_fusen_tags %in% + file.path(dummypackage, c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R")) + ) + ) + }) + + test_that("find_files_with_fusen_tags do not identify files not created by fusen", { + usethis::use_r("donotfindme.R", open = FALSE) + usethis::use_test("donotfindme.R", open = FALSE) + file.create(file.path(dummypackage, "vignettes", "donotfindme.Rmd")) + + files_with_fusen_tags <- find_files_with_fusen_tags() + expect_equal(length(files_with_fusen_tags), 3) + expect_true( + all( + files_with_fusen_tags %in% + file.path(dummypackage, c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R")) + ) + ) + }) +}) From 442728eb38b1cd84687f662a9ee65572f442ec8d Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Wed, 5 Jun 2024 11:40:57 +0200 Subject: [PATCH 08/19] feat(wip): Detecting and cleaning fusen tags in files #257 #259 --- R/sepuku_utils.R | 17 ++++++++ dev/flat_sepuku-utils.Rmd | 64 ++++++++++++++++++++++++++++++ tests/testthat/test-sepuku_utils.R | 37 +++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/R/sepuku_utils.R b/R/sepuku_utils.R index 75fa42c0..870784e2 100644 --- a/R/sepuku_utils.R +++ b/R/sepuku_utils.R @@ -121,3 +121,20 @@ find_files_with_fusen_tags <- function(pkg = ".") { return(files_with_fusen_tags) } + +#' @noRd +#' @rdname sepuku_utils +clean_fusen_tags_in_files <- function( + files_to_clean) { + fusen_tags <- tolower( + c("WARNING - Generated by", "Previously generated by", "WARNING - This vignette is generated by") + ) + + for (file in files_to_clean) { + lines <- readLines(file) + lines <- lines[!grepl(paste(fusen_tags, collapse = "|"), tolower(lines))] + writeLines(lines, file) + } + + return(files_to_clean) +} diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index 09a27b5b..f1270935 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -486,8 +486,72 @@ usethis::with_project(dummypackage, { ) }) }) +unlink(dummypackage, recursive = TRUE) ``` + +# clean_fusen_tags_in_files + +```{r function-clean_fusen_tags_in_files} +#' @noRd +#' @rdname sepuku_utils +clean_fusen_tags_in_files <- function( + files_to_clean) { + fusen_tags <- tolower( + c("WARNING - Generated by", "Previously generated by", "WARNING - This vignette is generated by") + ) + + for (file in files_to_clean) { + lines <- readLines(file) + lines <- lines[!grepl(paste(fusen_tags, collapse = "|"), tolower(lines))] + writeLines(lines, file) + } + + return(files_to_clean) +} +``` + + + +```{r tests-clean_fusen_tags_in_files} +test_that("clean_fusen_tags_in_files is a function", { + expect_true(inherits(clean_fusen_tags_in_files, "function")) +}) + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) +dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE +) +inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" +) +files_with_fusen_tags <- find_files_with_fusen_tags(pkg = dummypackage) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("clean_fusen_tags_in_files works with an empty pkg", { + cleaned_files <- clean_fusen_tags_in_files(files_with_fusen_tags) + cleaned_files_with_fusen_tags <- find_files_with_fusen_tags() + expect_equal(length(cleaned_files_with_fusen_tags), 0) + }) +}) +unlink(dummypackage, recursive = TRUE) +``` + + ```{r development-inflate, eval=FALSE} diff --git a/tests/testthat/test-sepuku_utils.R b/tests/testthat/test-sepuku_utils.R index a9401cfe..06bfeddb 100644 --- a/tests/testthat/test-sepuku_utils.R +++ b/tests/testthat/test-sepuku_utils.R @@ -318,3 +318,40 @@ usethis::with_project(dummypackage, { ) }) }) +unlink(dummypackage, recursive = TRUE) + +test_that("clean_fusen_tags_in_files is a function", { + expect_true(inherits(clean_fusen_tags_in_files, "function")) +}) + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) +dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE +) +inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" +) +files_with_fusen_tags <- find_files_with_fusen_tags(pkg = dummypackage) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("clean_fusen_tags_in_files works with an empty pkg", { + cleaned_files <- clean_fusen_tags_in_files(files_with_fusen_tags) + cleaned_files_with_fusen_tags <- find_files_with_fusen_tags() + expect_equal(length(cleaned_files_with_fusen_tags), 0) + }) +}) +unlink(dummypackage, recursive = TRUE) From 33683b601a3a33785c9e1e1efa19d80a7df6854a Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Thu, 6 Jun 2024 09:37:40 +0200 Subject: [PATCH 09/19] feat(wip): Modify sepuku utils funs to return relative paths #257 #259 --- R/sepuku_utils.R | 35 +++++++++++++++---------- dev/config_fusen.yaml | 1 - dev/flat_sepuku-utils.Rmd | 42 +++++++++++++++++------------- tests/testthat/test-sepuku_utils.R | 7 +++-- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/R/sepuku_utils.R b/R/sepuku_utils.R index 870784e2..2500e5b2 100644 --- a/R/sepuku_utils.R +++ b/R/sepuku_utils.R @@ -67,30 +67,36 @@ list_flat_files <- function(pkg = ".") { find_files_with_fusen_tags <- function(pkg = ".") { R_files_to_parse <- lapply( - c("R", "tests/testthat/"), + c("R", "tests/testthat"), function(folder) { - list.files( - path = file.path(pkg, folder), - pattern = "*\\.R", - full.names = TRUE + file.path( + folder, + list.files( + path = file.path(pkg, folder), + pattern = "*\\.R", + full.names = FALSE + ) ) } ) %>% - unlist() %>% - normalizePath() + unlist() + + Rmd_files_to_parse <- lapply( "vignettes", function(folder) { - list.files( - path = file.path(pkg, folder), - pattern = "*\\.Rmd", - full.names = TRUE + file.path( + folder, + list.files( + path = file.path(pkg, folder), + pattern = "*\\.Rmd", + full.names = FALSE + ) ) } ) %>% - unlist() %>% - normalizePath() + unlist() files_to_parse <- c(R_files_to_parse, Rmd_files_to_parse) @@ -125,13 +131,14 @@ find_files_with_fusen_tags <- function(pkg = ".") { #' @noRd #' @rdname sepuku_utils clean_fusen_tags_in_files <- function( + pkg = ".", files_to_clean) { fusen_tags <- tolower( c("WARNING - Generated by", "Previously generated by", "WARNING - This vignette is generated by") ) for (file in files_to_clean) { - lines <- readLines(file) + lines <- readLines(file.path(pkg, file)) lines <- lines[!grepl(paste(fusen_tags, collapse = "|"), tolower(lines))] writeLines(lines, file) } diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index 8205944f..28a33e43 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -153,7 +153,6 @@ flat_sepuku-utils.Rmd: check: false document: true overwrite: 'yes' - clean: ask keep: path: keep state: active diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index f1270935..e0415306 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -369,30 +369,36 @@ unlink(dummypackage, recursive = TRUE) find_files_with_fusen_tags <- function(pkg = ".") { R_files_to_parse <- lapply( - c("R", "tests/testthat/"), + c("R", "tests/testthat"), function(folder) { - list.files( - path = file.path(pkg, folder), - pattern = "*\\.R", - full.names = TRUE + file.path( + folder, + list.files( + path = file.path(pkg, folder), + pattern = "*\\.R", + full.names = FALSE + ) ) } ) %>% - unlist() %>% - normalizePath() + unlist() + + Rmd_files_to_parse <- lapply( "vignettes", function(folder) { - list.files( - path = file.path(pkg, folder), - pattern = "*\\.Rmd", - full.names = TRUE + file.path( + folder, + list.files( + path = file.path(pkg, folder), + pattern = "*\\.Rmd", + full.names = FALSE + ) ) } ) %>% - unlist() %>% - normalizePath() + unlist() files_to_parse <- c(R_files_to_parse, Rmd_files_to_parse) @@ -437,7 +443,6 @@ fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") - test_that("find_files_with_fusen_tags works with an empty pkg", { files_with_fusen_tags <- find_files_with_fusen_tags() expect_equal(length(files_with_fusen_tags), 0) @@ -466,7 +471,7 @@ usethis::with_project(dummypackage, { expect_true( all( files_with_fusen_tags %in% - file.path(dummypackage, c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R")) + c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R") ) ) }) @@ -481,7 +486,7 @@ usethis::with_project(dummypackage, { expect_true( all( files_with_fusen_tags %in% - file.path(dummypackage, c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R")) + c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R") ) ) }) @@ -496,13 +501,14 @@ unlink(dummypackage, recursive = TRUE) #' @noRd #' @rdname sepuku_utils clean_fusen_tags_in_files <- function( + pkg = ".", files_to_clean) { fusen_tags <- tolower( c("WARNING - Generated by", "Previously generated by", "WARNING - This vignette is generated by") ) for (file in files_to_clean) { - lines <- readLines(file) + lines <- readLines(file.path(pkg, file)) lines <- lines[!grepl(paste(fusen_tags, collapse = "|"), tolower(lines))] writeLines(lines, file) } @@ -543,7 +549,7 @@ usethis::with_project(dummypackage, { usethis::use_mit_license("John Doe") test_that("clean_fusen_tags_in_files works with an empty pkg", { - cleaned_files <- clean_fusen_tags_in_files(files_with_fusen_tags) + cleaned_files <- clean_fusen_tags_in_files(pkg = dummypackage, files_to_clean = files_with_fusen_tags) cleaned_files_with_fusen_tags <- find_files_with_fusen_tags() expect_equal(length(cleaned_files_with_fusen_tags), 0) }) diff --git a/tests/testthat/test-sepuku_utils.R b/tests/testthat/test-sepuku_utils.R index 06bfeddb..0144b5e3 100644 --- a/tests/testthat/test-sepuku_utils.R +++ b/tests/testthat/test-sepuku_utils.R @@ -269,7 +269,6 @@ fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") - test_that("find_files_with_fusen_tags works with an empty pkg", { files_with_fusen_tags <- find_files_with_fusen_tags() expect_equal(length(files_with_fusen_tags), 0) @@ -298,7 +297,7 @@ usethis::with_project(dummypackage, { expect_true( all( files_with_fusen_tags %in% - file.path(dummypackage, c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R")) + c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R") ) ) }) @@ -313,7 +312,7 @@ usethis::with_project(dummypackage, { expect_true( all( files_with_fusen_tags %in% - file.path(dummypackage, c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R")) + c("R/flat1_rmd.R", "vignettes/get-started.Rmd", "tests/testthat/test-flat1_rmd.R") ) ) }) @@ -349,7 +348,7 @@ usethis::with_project(dummypackage, { usethis::use_mit_license("John Doe") test_that("clean_fusen_tags_in_files works with an empty pkg", { - cleaned_files <- clean_fusen_tags_in_files(files_with_fusen_tags) + cleaned_files <- clean_fusen_tags_in_files(pkg = dummypackage, files_to_clean = files_with_fusen_tags) cleaned_files_with_fusen_tags <- find_files_with_fusen_tags() expect_equal(length(cleaned_files_with_fusen_tags), 0) }) From 7fe214fd2d101477a5731748f759864ca801b4c0 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Thu, 6 Jun 2024 10:21:25 +0200 Subject: [PATCH 10/19] feat(wip): Adapting sepuku tests with mocked binding for readline #257 --- dev/flat_sepuku.Rmd | 326 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 288 insertions(+), 38 deletions(-) diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index ba85c2d2..641f2462 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -24,7 +24,8 @@ pkgload::load_all(export_all = FALSE) #' #' @examples sepuku <- function( - pkg = ".") { + pkg = ".", + force = FALSE) { if (!dir.exists(file.path(pkg, "dev"))) { cli::cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") } @@ -32,10 +33,90 @@ sepuku <- function( config_file <- getOption("fusen.config_file", default = "dev/config_fusen.yaml") if (!file.exists(config_file)) { - cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as files starting with 'flat' in the dev/ folder.") + cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") } else { - cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as those starting with 'flat' in the dev/ folder.") + cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") } + + flat_files <- list_flat_files(pkg = pkg) + + if (length(flat_files) == 0) { + cli::cli_alert_info("No flat files were detected.") + } else { + cli::cli_alert_info("The following flat files were detected and will therefore be deleted from your package:") + invisible( + lapply( + flat_files, + function(f) { + cli::cli_alert(f) + } + ) + ) + } + + files_to_be_modified <- find_files_with_fusen_tags(pkg = pkg) + if (length(files_to_be_modified) == 0) { + cli::cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.") + } else { + cli::cli_alert_info("The following files have been identified as containing fusen-related tags and will therefore be modified:") + invisible( + lapply( + files_to_be_modified, + function(f) { + cli::cli_alert(f) + } + ) + ) + } + + if (length(flat_files) == 0 && length(files_to_be_modified) == 0) { + return(invisible(NULL)) + } + + do_it <- force + + if (!force) { + cli::cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") + sure <- paste( + "\nAre you sure of what you are doing? (y/n)\n" + ) + clean <- readline(sure) == "y" || readline(sure) == "yes" + if (isTRUE(clean) || clean == "yes") { + do_it <- TRUE + } else if (isFALSE(clean) || clean == "no") { + do_it <- FALSE + } else { + stop("clean should be TRUE, FALSE, 'yes'or 'no'") + } + } + + if (isTRUE(do_it)) { + if (length(flat_files) > 0) { + invisible( + lapply( + flat_files, + function(f) { + cli::cli_alert(paste0("Deleting ", f)) + file.remove(file.path(pkg, f)) + } + ) + ) + } + + if (length(files_to_be_modified) > 0) { + invisible( + lapply( + files_to_be_modified, + function(f) { + cli::cli_alert(paste0("Editing ", f)) + clean_fusen_tags_in_files(pkg = pkg, files_to_clean = f) + } + ) + ) + } + } + + # print(files_to_be_modified) } ``` @@ -44,7 +125,7 @@ sepuku() ``` ```{r tests-sepuku} -dummypackage <- tempfile("sepuku.first") +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) @@ -59,40 +140,49 @@ usethis::with_project(dummypackage, { test_that("sepuku checks that a dev/ folder exists", { #  Check for a dev folder expect_error( - sepuku(), "No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?" + sepuku(force = TRUE), + "No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?" ) }) - dev_file <- suppressMessages(add_minimal_package(overwrite = TRUE, open = FALSE)) test_that("sepuku checks whether a fusen config file exists or not", { + dir.create(file.path(dummypackage, "dev")) expect_message( - sepuku(), "No fusen configuration file found. The flat files to be deleted will be identified as files starting with 'flat' in the dev/ folder." + sepuku(force = TRUE), + "No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders." ) + }) - # To add the config file a first inflate is needed - flat_file <- dev_file[grepl("flat_", dev_file)] + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) - suppressMessages( - inflate( - pkg = dummypackage, flat_file = flat_file, - vignette_name = "Get started", check = FALSE, - open_vignette = FALSE, document = TRUE, - overwrite = "yes" - ) + # To add the config file a first inflate is needed + suppressMessages( + inflate( + pkg = dummypackage, flat_file = dev_file1, + vignette_name = "Get started", check = FALSE, + open_vignette = FALSE, document = TRUE, + overwrite = "yes" ) + ) - expect_message( - sepuku(), "A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as those starting with 'flat' in the dev/ folder." - ) - }) + expect_message( + sepuku(force = TRUE), + "A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders." + ) }) + unlink(dummypackage, recursive = TRUE) ``` + ```{r tests-sepuku} -dummypackage <- tempfile("sepuku.second") +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) @@ -101,41 +191,201 @@ usethis::with_project(dummypackage, { usethis::use_mit_license("John Doe") browser() - test_that("sepuku raises a message if no flat files have been found", { - #  Check for a dev folder - expect_error( - sepuku(), "No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?" + + dir.create(file.path(dummypackage, "dev")) + + test_that("sepuku warns the user if no flat files were detected", { + expect_message( + sepuku(force = TRUE), + "No flat files were detected." ) }) - dev_file <- suppressMessages(add_minimal_package(overwrite = TRUE, open = FALSE)) - test_that("sepuku checks whether a fusen config file exists or not", { + test_that("sepuku informs the user about the flat files that were detected", { + dir.create(file.path(dummypackage, "dev", "flat_history")) + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.Rmd")) + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.qmd")) + file.create(file.path(dummypackage, "dev", "flat_qmd.qmd")) + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + + expect_message( + sepuku(force = TRUE), + "The following flat files were detected and will therefore be deleted from your package:" + ) + expect_message( + sepuku(force = TRUE), + "dev/flat_flat1.Rmd" + ) + expect_message( + sepuku(force = TRUE), + "dev/flat_qmd.qmd" + ) + expect_message( + sepuku(force = TRUE), + "dev/flat_history/flat_old.qmd" + ) + expect_message( + sepuku(force = TRUE), + "dev/flat_history/flat_old.Rmd" + ) + }) +}) +unlink(dummypackage, recursive = TRUE) + + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + dir.create(file.path(dummypackage, "dev")) + usethis::use_r("some_R_file.R", open = FALSE) + usethis::use_test("some_test.R", open = FALSE) + dir.create(file.path(dummypackage, "vignettes")) + file.create(file.path(dummypackage, "vignettes", "somevignette.Rmd")) + + + test_that("sepuku warns the user if no files in R, tests or vignettes have to be modified", { + expect_message( + sepuku(force = TRUE), + "No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders." + ) + }) + + test_that("sepuku informs the user about the files with fusen tags that were detected", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + dev_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat2.Rmd", + open = FALSE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + + expect_message( + sepuku(force = TRUE), + "The following files have been identified as containing fusen-related tags and will therefore be modified:" + ) + expect_message( + sepuku(force = TRUE), + "R/flat1_rmd.R" + ) + expect_message( + sepuku(force = TRUE), + "R/flat2_rmd.R" + ) + expect_message( - sepuku(), "No fusen configuration file found. The flat files to be deleted will be identified as files starting with 'flat' in the dev/ folder." + sepuku(force = TRUE), + "tests/testthat/test-flat1_rmd.R" ) - # To add the config file a first inflate is needed - flat_file <- dev_file[grepl("flat_", dev_file)] + expect_message( + sepuku(force = TRUE), + "tests/testthat/test-flat2_rmd.R" + ) + + expect_message( + sepuku(force = TRUE), + "vignettes/get-started.Rmd" + ) + expect_message( + sepuku(force = TRUE), + "vignettes/get-started-2.Rmd" + ) + }) - suppressMessages( - inflate( - pkg = dummypackage, flat_file = flat_file, - vignette_name = "Get started", check = FALSE, - open_vignette = FALSE, document = TRUE, - overwrite = "yes" + if (interactive()) { + test_that("sepuku tells the users that files will be modified or deleted and that it is irreversible", { + expect_message( + sepuku(force = FALSE), + "Some files are about to be deleted or modified. This operation is irreversible." ) + }) + } + browser() + + test_that("sepuku tells the users when it starts deleting flat files", { + expect_message( + sepuku(force = TRUE), + "Deleting dev/flat_flat1.Rmd" + ) + expect_message( + sepuku(force = TRUE), + "Deleting dev/flat_flat2.Rmd" ) + }) + test_that("sepuku tells the users when it starts modifiying flat files", { + expect_message( + sepuku(force = TRUE), + "Editing R/flat1_rmd.R" + ) + expect_message( + sepuku(force = TRUE), + "Editing R/flat2_rmd.R" + ) + expect_message( + sepuku(force = TRUE), + "Editing tests/testthat/test-flat1_rmd.R" + ) expect_message( - sepuku(), "A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as those starting with 'flat' in the dev/ folder." + sepuku(force = TRUE), + "Editing tests/testthat/test-flat2_rmd.R" + ) + expect_message( + sepuku(force = TRUE), + "Editing vignettes/get-started.Rmd" + ) + expect_message( + sepuku(force = TRUE), + "Editing vignettes/get-started-2.Rmd" ) }) }) - unlink(dummypackage, recursive = TRUE) ``` + ```{r development-inflate, eval=FALSE} # Run but keep eval=FALSE to avoid infinite loop # Execute in the console directly From c4eaf8330f66f542a1c5995dfd3ee82b404979f9 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Thu, 6 Jun 2024 12:03:31 +0200 Subject: [PATCH 11/19] feat(wip): sepuku ready doc to be made one test failing in non interactive #257 --- NAMESPACE | 1 + R/sepuku.R | 101 +++++++++++++ dev/config_fusen.yaml | 14 ++ dev/flat_sepuku.Rmd | 242 +++++++++++++++++-------------- man/sepuku.Rd | 17 +++ tests/testthat/test-sepuku.R | 274 +++++++++++++++++++++++++++++++++++ 6 files changed, 538 insertions(+), 111 deletions(-) create mode 100644 R/sepuku.R create mode 100644 man/sepuku.Rd create mode 100644 tests/testthat/test-sepuku.R diff --git a/NAMESPACE b/NAMESPACE index d14b8148..0483ff67 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ export(list_flat_files) export(load_flat_functions) export(register_all_to_config) export(rename_flat_file) +export(sepuku) importFrom(attachment,att_amend_desc) importFrom(cli,cat_rule) importFrom(cli,cli_alert_danger) diff --git a/R/sepuku.R b/R/sepuku.R new file mode 100644 index 00000000..b9f8d1c0 --- /dev/null +++ b/R/sepuku.R @@ -0,0 +1,101 @@ +# WARNING - Generated by {fusen} from dev/flat_sepuku.Rmd: do not edit by hand + +#' sepuku Title +#' +#' @return 1 +#' @export +#' +#' @examples +#' sepuku() +sepuku <- function( + pkg = ".", + force = FALSE) { + if (!dir.exists(file.path(pkg, "dev"))) { + cli::cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") + } + + config_file <- getOption("fusen.config_file", default = "dev/config_fusen.yaml") + + if (!file.exists(config_file)) { + cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") + } else { + cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted.") + } + + flat_files <- list_flat_files(pkg = pkg) + + if (length(flat_files) == 0) { + cli::cli_alert_info("No flat files were detected.") + } else { + cli::cli_alert_info( + paste0( + "The following flat files were detected and will therefore be deleted from your package:\n", + paste0(flat_files, collapse = "\n") + ) + ) + } + + files_to_be_modified <- find_files_with_fusen_tags(pkg = pkg) + if (length(files_to_be_modified) == 0) { + cli::cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.") + } else { + cli::cli_alert_info( + paste0( + "The following files have been identified as containing fusen-related tags and will therefore be modified:\n", + paste0(files_to_be_modified, collapse = "\n") + ) + ) + } + + if (length(flat_files) == 0 && length(files_to_be_modified) == 0) { + return(invisible(NULL)) + } + + do_it <- force + + if (!force) { + cli::cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") + sure <- paste( + "\nAre you sure of what you are doing? (y/n)\n" + ) + clean <- readline(sure) == "y" || readline(sure) == "yes" + if (isTRUE(clean) || clean == "yes") { + do_it <- TRUE + } else if (isFALSE(clean) || clean == "no") { + do_it <- FALSE + } else { + stop("clean should be TRUE, FALSE, 'yes'or 'no'") + } + } + + if (isTRUE(do_it)) { + if (length(flat_files) > 0) { + invisible( + lapply( + flat_files, + function(f) { + file.remove(file.path(pkg, f)) + } + ) + ) + } + + if (length(files_to_be_modified) > 0) { + invisible( + lapply( + files_to_be_modified, + function(f) { + clean_fusen_tags_in_files(pkg = pkg, files_to_clean = f) + } + ) + ) + } + if (file.exists(config_file)) { + file.remove(config_file) + } + } + + cli::cli_alert_info("Cleaning is done !") + + return(invisible(TRUE)) +} diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index 28a33e43..dcf11228 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -140,6 +140,20 @@ flat_register_config_file.Rmd: document: true overwrite: 'yes' clean: ask +flat_sepuku.Rmd: + path: dev/flat_sepuku.Rmd + state: active + R: R/sepuku.R + tests: tests/testthat/test-sepuku.R + vignettes: [] + inflate: + flat_file: dev/flat_sepuku.Rmd + vignette_name: .na + open_vignette: false + check: false + document: true + overwrite: 'yes' + clean: ask flat_sepuku-utils.Rmd: path: dev/flat_sepuku-utils.Rmd state: active diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index 641f2462..bf42f775 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -35,7 +35,7 @@ sepuku <- function( if (!file.exists(config_file)) { cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") } else { - cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") + cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted.") } flat_files <- list_flat_files(pkg = pkg) @@ -43,13 +43,10 @@ sepuku <- function( if (length(flat_files) == 0) { cli::cli_alert_info("No flat files were detected.") } else { - cli::cli_alert_info("The following flat files were detected and will therefore be deleted from your package:") - invisible( - lapply( - flat_files, - function(f) { - cli::cli_alert(f) - } + cli::cli_alert_info( + paste0( + "The following flat files were detected and will therefore be deleted from your package:\n", + paste0(flat_files, collapse = "\n") ) ) } @@ -58,13 +55,10 @@ sepuku <- function( if (length(files_to_be_modified) == 0) { cli::cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.") } else { - cli::cli_alert_info("The following files have been identified as containing fusen-related tags and will therefore be modified:") - invisible( - lapply( - files_to_be_modified, - function(f) { - cli::cli_alert(f) - } + cli::cli_alert_info( + paste0( + "The following files have been identified as containing fusen-related tags and will therefore be modified:\n", + paste0(files_to_be_modified, collapse = "\n") ) ) } @@ -96,7 +90,6 @@ sepuku <- function( lapply( flat_files, function(f) { - cli::cli_alert(paste0("Deleting ", f)) file.remove(file.path(pkg, f)) } ) @@ -108,15 +101,19 @@ sepuku <- function( lapply( files_to_be_modified, function(f) { - cli::cli_alert(paste0("Editing ", f)) clean_fusen_tags_in_files(pkg = pkg, files_to_clean = f) } ) ) } + if (file.exists(config_file)) { + file.remove(config_file) + } } - # print(files_to_be_modified) + cli::cli_alert_info("Cleaning is done !") + + return(invisible(TRUE)) } ``` @@ -172,7 +169,7 @@ usethis::with_project(dummypackage, { expect_message( sepuku(force = TRUE), - "A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders." + "A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted." ) }) @@ -190,10 +187,9 @@ usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") - browser() - dir.create(file.path(dummypackage, "dev")) + test_that("sepuku warns the user if no flat files were detected", { expect_message( sepuku(force = TRUE), @@ -202,6 +198,7 @@ usethis::with_project(dummypackage, { }) + test_that("sepuku informs the user about the flat files that were detected", { dir.create(file.path(dummypackage, "dev", "flat_history")) file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.Rmd")) @@ -222,26 +219,9 @@ usethis::with_project(dummypackage, { overwrite = "yes" ) - - expect_message( - sepuku(force = TRUE), - "The following flat files were detected and will therefore be deleted from your package:" - ) expect_message( sepuku(force = TRUE), - "dev/flat_flat1.Rmd" - ) - expect_message( - sepuku(force = TRUE), - "dev/flat_qmd.qmd" - ) - expect_message( - sepuku(force = TRUE), - "dev/flat_history/flat_old.qmd" - ) - expect_message( - sepuku(force = TRUE), - "dev/flat_history/flat_old.Rmd" + "The following flat files were detected and will therefore be deleted from your package:\ndev/flat_flat1.Rmd\ndev/flat_qmd.qmd\ndev/flat_history/flat_old.Rmd\ndev/flat_history/flat_old.qmd" ) }) }) @@ -265,11 +245,13 @@ usethis::with_project(dummypackage, { test_that("sepuku warns the user if no files in R, tests or vignettes have to be modified", { expect_message( - sepuku(force = TRUE), + sepuku(force = FALSE), "No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders." ) }) + + test_that("sepuku informs the user about the files with fusen tags that were detected", { dev_file1 <- add_minimal_flat( pkg = dummypackage, @@ -300,95 +282,133 @@ usethis::with_project(dummypackage, { overwrite = "yes" ) + # if (interactive()) { + # test_that("sepuku tells the users that files will be modified or deleted and that it is irreversible", { + # expect_message( + # sepuku(force = FALSE), + # "Some files are about to be deleted or modified. This operation is irreversible." + # ) + # }) + # } expect_message( sepuku(force = TRUE), - "The following files have been identified as containing fusen-related tags and will therefore be modified:" - ) - expect_message( - sepuku(force = TRUE), - "R/flat1_rmd.R" - ) - expect_message( - sepuku(force = TRUE), - "R/flat2_rmd.R" + "The following files have been identified as containing fusen-related tags and will therefore be modified:\nR/flat1_rmd.R\nR/flat2_rmd.R\ntests/testthat/test-flat1_rmd.R\ntests/testthat/test-flat2_rmd.R\nvignettes/get-started-2.Rmd\nvignettes/get-started.Rmd" ) + }) +}) +unlink(dummypackage, recursive = TRUE) - expect_message( - sepuku(force = TRUE), - "tests/testthat/test-flat1_rmd.R" - ) +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) - expect_message( - sepuku(force = TRUE), - "tests/testthat/test-flat2_rmd.R" - ) +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") - expect_message( - sepuku(force = TRUE), - "vignettes/get-started.Rmd" - ) - expect_message( - sepuku(force = TRUE), - "vignettes/get-started-2.Rmd" + dir.create(file.path(dummypackage, "dev")) + dir.create(file.path(dummypackage, "dev", "flat_history")) + + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + + dev_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat2.Rmd", + open = FALSE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + deprecate_flat_file( + file.path(dummypackage, "dev", "flat_flat1.Rmd") + ) + + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.qmd")) + file.create(file.path(dummypackage, "dev", "flat_qmd.qmd")) + + sepuku(force = TRUE) + + expect_false( + file.exists( + file.path(dummypackage, "dev", "config_fusen.yaml") ) - }) + ) + expect_equal( + length( + list.files(file.path(dummypackage, "dev"), + pattern = "flat_.*\\.Rmd" + ) + ), + 0 + ) - if (interactive()) { - test_that("sepuku tells the users that files will be modified or deleted and that it is irreversible", { - expect_message( - sepuku(force = FALSE), - "Some files are about to be deleted or modified. This operation is irreversible." + expect_equal( + length( + list.files(file.path(dummypackage, "dev"), + pattern = "flat_.*\\.qmd" ) - }) - } - browser() + ), + 0 + ) - test_that("sepuku tells the users when it starts deleting flat files", { - expect_message( - sepuku(force = TRUE), - "Deleting dev/flat_flat1.Rmd" - ) - expect_message( - sepuku(force = TRUE), - "Deleting dev/flat_flat2.Rmd" - ) - }) + expect_equal( + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "flat_.*\\.Rmd" + ) + ), + 0 + ) - test_that("sepuku tells the users when it starts modifiying flat files", { - expect_message( - sepuku(force = TRUE), - "Editing R/flat1_rmd.R" - ) - expect_message( - sepuku(force = TRUE), - "Editing R/flat2_rmd.R" - ) - expect_message( - sepuku(force = TRUE), - "Editing tests/testthat/test-flat1_rmd.R" - ) - expect_message( - sepuku(force = TRUE), - "Editing tests/testthat/test-flat2_rmd.R" - ) - expect_message( - sepuku(force = TRUE), - "Editing vignettes/get-started.Rmd" - ) - expect_message( - sepuku(force = TRUE), - "Editing vignettes/get-started-2.Rmd" - ) - }) + expect_equal( + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "flat_.*\\.qmd" + ) + ), + 0 + ) + + expect_equal( + length(find_files_with_fusen_tags(pkg = dummypackage)), + 0 + ) }) -unlink(dummypackage, recursive = TRUE) ``` ```{r development-inflate, eval=FALSE} # Run but keep eval=FALSE to avoid infinite loop # Execute in the console directly -fusen::inflate(flat_file = "dev/flat_sepuku.Rmd", vignette_name = "Go further") +fusen::inflate( + flat_file = "dev/flat_sepuku.Rmd", + vignette_name = NA, + check = FALSE, + overwrite = TRUE, + open_vignette = FALSE +) ``` diff --git a/man/sepuku.Rd b/man/sepuku.Rd new file mode 100644 index 00000000..8856e5ad --- /dev/null +++ b/man/sepuku.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sepuku.R +\name{sepuku} +\alias{sepuku} +\title{sepuku Title} +\usage{ +sepuku(pkg = ".", force = FALSE) +} +\value{ +1 +} +\description{ +sepuku Title +} +\examples{ +sepuku() +} diff --git a/tests/testthat/test-sepuku.R b/tests/testthat/test-sepuku.R new file mode 100644 index 00000000..437a0ff1 --- /dev/null +++ b/tests/testthat/test-sepuku.R @@ -0,0 +1,274 @@ +# WARNING - Generated by {fusen} from dev/flat_sepuku.Rmd: do not edit by hand + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +test_that("sepuku is a function", { + expect_true(inherits(sepuku, "function")) +}) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + test_that("sepuku checks that a dev/ folder exists", { + #  Check for a dev folder + expect_error( + sepuku(force = TRUE), + "No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?" + ) + }) + + + test_that("sepuku checks whether a fusen config file exists or not", { + dir.create(file.path(dummypackage, "dev")) + expect_message( + sepuku(force = TRUE), + "No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders." + ) + }) + + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + + # To add the config file a first inflate is needed + suppressMessages( + inflate( + pkg = dummypackage, flat_file = dev_file1, + vignette_name = "Get started", check = FALSE, + open_vignette = FALSE, document = TRUE, + overwrite = "yes" + ) + ) + + expect_message( + sepuku(force = TRUE), + "A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted." + ) +}) + + +unlink(dummypackage, recursive = TRUE) + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + dir.create(file.path(dummypackage, "dev")) + + + test_that("sepuku warns the user if no flat files were detected", { + expect_message( + sepuku(force = TRUE), + "No flat files were detected." + ) + }) + + + + test_that("sepuku informs the user about the flat files that were detected", { + dir.create(file.path(dummypackage, "dev", "flat_history")) + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.Rmd")) + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.qmd")) + file.create(file.path(dummypackage, "dev", "flat_qmd.qmd")) + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + expect_message( + sepuku(force = TRUE), + "The following flat files were detected and will therefore be deleted from your package:\ndev/flat_flat1.Rmd\ndev/flat_qmd.qmd\ndev/flat_history/flat_old.Rmd\ndev/flat_history/flat_old.qmd" + ) + }) +}) +unlink(dummypackage, recursive = TRUE) + + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + dir.create(file.path(dummypackage, "dev")) + usethis::use_r("some_R_file.R", open = FALSE) + usethis::use_test("some_test.R", open = FALSE) + dir.create(file.path(dummypackage, "vignettes")) + file.create(file.path(dummypackage, "vignettes", "somevignette.Rmd")) + + + test_that("sepuku warns the user if no files in R, tests or vignettes have to be modified", { + expect_message( + sepuku(force = FALSE), + "No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders." + ) + }) + + + + test_that("sepuku informs the user about the files with fusen tags that were detected", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + dev_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat2.Rmd", + open = FALSE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + # if (interactive()) { + # test_that("sepuku tells the users that files will be modified or deleted and that it is irreversible", { + # expect_message( + # sepuku(force = FALSE), + # "Some files are about to be deleted or modified. This operation is irreversible." + # ) + # }) + # } + + expect_message( + sepuku(force = TRUE), + "The following files have been identified as containing fusen-related tags and will therefore be modified:\nR/flat1_rmd.R\nR/flat2_rmd.R\ntests/testthat/test-flat1_rmd.R\ntests/testthat/test-flat2_rmd.R\nvignettes/get-started-2.Rmd\nvignettes/get-started.Rmd" + ) + }) +}) +unlink(dummypackage, recursive = TRUE) + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + dir.create(file.path(dummypackage, "dev")) + dir.create(file.path(dummypackage, "dev", "flat_history")) + + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + + dev_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat2.Rmd", + open = FALSE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + deprecate_flat_file( + file.path(dummypackage, "dev", "flat_flat1.Rmd") + ) + + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.qmd")) + file.create(file.path(dummypackage, "dev", "flat_qmd.qmd")) + + sepuku(force = TRUE) + + expect_false( + file.exists( + file.path(dummypackage, "dev", "config_fusen.yaml") + ) + ) + expect_equal( + length( + list.files(file.path(dummypackage, "dev"), + pattern = "flat_.*\\.Rmd" + ) + ), + 0 + ) + + expect_equal( + length( + list.files(file.path(dummypackage, "dev"), + pattern = "flat_.*\\.qmd" + ) + ), + 0 + ) + + expect_equal( + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "flat_.*\\.Rmd" + ) + ), + 0 + ) + + expect_equal( + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "flat_.*\\.qmd" + ) + ), + 0 + ) + + expect_equal( + length(find_files_with_fusen_tags(pkg = dummypackage)), + 0 + ) +}) From a5b5cd2f2bc14f16e85a4db0d6d2c295eeff89a4 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Fri, 7 Jun 2024 10:41:01 +0200 Subject: [PATCH 12/19] test: Fixing unit tests #257 --- R/sepuku.R | 107 +++++++++++++++++++- dev/flat_sepuku-utils.Rmd | 36 +++---- dev/flat_sepuku.Rmd | 156 ++++++++++++++++++++++++++--- man/sepuku.Rd | 112 ++++++++++++++++++++- tests/testthat/test-sepuku.R | 46 +++++++-- tests/testthat/test-sepuku_utils.R | 36 +++---- 6 files changed, 430 insertions(+), 63 deletions(-) diff --git a/R/sepuku.R b/R/sepuku.R index b9f8d1c0..d24217e5 100644 --- a/R/sepuku.R +++ b/R/sepuku.R @@ -1,12 +1,113 @@ # WARNING - Generated by {fusen} from dev/flat_sepuku.Rmd: do not edit by hand -#' sepuku Title +#' Clean a package from fusen-related files and tags +#' This function will remove all the flat files and the fusen-related tags from the package. It will also remove the configuration file if it exists. #' -#' @return 1 +#' @param pkg Character. Path of the current package +#' @param force logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE) +#' @return a cleaned package #' @export -#' #' @examples +#' \dontrun{ #' sepuku() +#' # If you want to force the cleaning, you can use the force argument +#' sepuku(force = TRUE) +#' +#' # Example with a dummy package with a flat file +#' dummypackage <- tempfile("sepuku.example") +#' dir.create(dummypackage) +#' fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) +#' +#' usethis::with_project(dummypackage, { +#' # Add licence +#' usethis::use_mit_license("John Doe") +#' +#' dir.create(file.path(dummypackage, "dev")) +#' dir.create(file.path(dummypackage, "dev", "flat_history")) +#' +#' # We add 2 flat files in the package and inflate them +#' dev_file1 <- add_minimal_flat( +#' pkg = dummypackage, +#' flat_name = "flat1.Rmd", +#' open = FALSE +#' ) +#' +#' dev_file2 <- add_minimal_flat( +#' pkg = dummypackage, +#' flat_name = "flat2.Rmd", +#' open = FALSE +#' ) +#' +#' inflate( +#' pkg = dummypackage, +#' flat_file = dev_file1, +#' vignette_name = "Get started", +#' check = FALSE, +#' open_vignette = FALSE, +#' document = TRUE, +#' overwrite = "yes" +#' ) +#' +#' inflate( +#' pkg = dummypackage, +#' flat_file = dev_file2, +#' vignette_name = "Get started 2", +#' check = FALSE, +#' open_vignette = FALSE, +#' document = TRUE, +#' overwrite = "yes" +#' ) +#' +#' # We deprecate the first flat file, which will be moved to the flat_history folder +#' deprecate_flat_file( +#' file.path(dummypackage, "dev", "flat_flat1.Rmd") +#' ) +#' +#' # We create 2 flat files with the qmd extension +#' file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.qmd")) +#' file.create(file.path(dummypackage, "dev", "flat_qmd.qmd")) +#' +#' sepuku(force = TRUE) +#' +#' # We check that the fusen configuration file has been deleted +#' file.exists( +#' file.path(dummypackage, "dev", "config_fusen.yaml") +#' ) +#' +#' # We check that all the flat files have been deleted +#' length( +#' list.files(file.path(dummypackage, "dev"), +#' pattern = "flat_.*\\.Rmd" +#' ) +#' ) +#' +#' length( +#' list.files(file.path(dummypackage, "dev"), +#' pattern = "flat_.*\\.qmd" +#' ) +#' ) +#' +#' +#' length( +#' list.files(file.path(dummypackage, "dev", "flat_history"), +#' pattern = "flat_.*\\.Rmd" +#' ) +#' ) +#' +#' +#' length( +#' list.files(file.path(dummypackage, "dev", "flat_history"), +#' pattern = "flat_.*\\.qmd" +#' ) +#' ) +#' +#' # We check that all the files with fusen tags have been cleaned +#' length(fusen:::find_files_with_fusen_tags(pkg = dummypackage)) +#' }) +#' +#' # Clean the temporary directory +#' unlink(dummypackage, recursive = TRUE) +#' } sepuku <- function( pkg = ".", force = FALSE) { diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index e0415306..2c314fe1 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -527,27 +527,29 @@ test_that("clean_fusen_tags_in_files is a function", { dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) -dev_file1 <- add_minimal_flat( - pkg = dummypackage, - flat_name = "flat1.Rmd", - open = FALSE, - overwrite = TRUE -) -inflate( - pkg = dummypackage, - flat_file = dev_file1, - vignette_name = "Get started", - check = FALSE, - open_vignette = FALSE, - document = TRUE, - overwrite = "yes" -) -files_with_fusen_tags <- find_files_with_fusen_tags(pkg = dummypackage) - usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + files_with_fusen_tags <- find_files_with_fusen_tags(pkg = dummypackage) + + + test_that("clean_fusen_tags_in_files works with an empty pkg", { cleaned_files <- clean_fusen_tags_in_files(pkg = dummypackage, files_to_clean = files_with_fusen_tags) cleaned_files_with_fusen_tags <- find_files_with_fusen_tags() diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index bf42f775..d22221ca 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -17,12 +17,13 @@ pkgload::load_all(export_all = FALSE) # sepuku ```{r function-sepuku} -#' sepuku Title +#' Clean a package from fusen-related files and tags +#' This function will remove all the flat files and the fusen-related tags from the package. It will also remove the configuration file if it exists. #' -#' @return 1 +#' @param pkg Character. Path of the current package +#' @param force logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE) +#' @return a cleaned package #' @export -#' -#' @examples sepuku <- function( pkg = ".", force = FALSE) { @@ -117,8 +118,107 @@ sepuku <- function( } ``` -```{r examples-sepuku} +```{r examples-sepuku, eval=FALSE} +#' \dontrun{ sepuku() +# If you want to force the cleaning, you can use the force argument +sepuku(force = TRUE) + +# Example with a dummy package with a flat file +dummypackage <- tempfile("sepuku.example") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + dir.create(file.path(dummypackage, "dev")) + dir.create(file.path(dummypackage, "dev", "flat_history")) + + # We add 2 flat files in the package and inflate them + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + + dev_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat2.Rmd", + open = FALSE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + # We deprecate the first flat file, which will be moved to the flat_history folder + deprecate_flat_file( + file.path(dummypackage, "dev", "flat_flat1.Rmd") + ) + + # We create 2 flat files with the qmd extension + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.qmd")) + file.create(file.path(dummypackage, "dev", "flat_qmd.qmd")) + + sepuku(force = TRUE) + + # We check that the fusen configuration file has been deleted + file.exists( + file.path(dummypackage, "dev", "config_fusen.yaml") + ) + + # We check that all the flat files have been deleted + length( + list.files(file.path(dummypackage, "dev"), + pattern = "flat_.*\\.Rmd" + ) + ) + + length( + list.files(file.path(dummypackage, "dev"), + pattern = "flat_.*\\.qmd" + ) + ) + + + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "flat_.*\\.Rmd" + ) + ) + + + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "flat_.*\\.qmd" + ) + ) + + # We check that all the files with fusen tags have been cleaned + length(fusen:::find_files_with_fusen_tags(pkg = dummypackage)) +}) + +# Clean the temporary directory +unlink(dummypackage, recursive = TRUE) +#' } ``` ```{r tests-sepuku} @@ -282,15 +382,6 @@ usethis::with_project(dummypackage, { overwrite = "yes" ) - # if (interactive()) { - # test_that("sepuku tells the users that files will be modified or deleted and that it is irreversible", { - # expect_message( - # sepuku(force = FALSE), - # "Some files are about to be deleted or modified. This operation is irreversible." - # ) - # }) - # } - expect_message( sepuku(force = TRUE), "The following files have been identified as containing fusen-related tags and will therefore be modified:\nR/flat1_rmd.R\nR/flat2_rmd.R\ntests/testthat/test-flat1_rmd.R\ntests/testthat/test-flat2_rmd.R\nvignettes/get-started-2.Rmd\nvignettes/get-started.Rmd" @@ -303,6 +394,43 @@ dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + test_that("sepuku informs the user than modifying / deleting files can not be undone if force = FALSE", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + + if (interactive()) { + test_that("sepuku tells the users that files will be modified or deleted and that it is irreversible", { + expect_message( + sepuku(force = FALSE), + "Some files are about to be deleted or modified. This operation is irreversible." + ) + }) + } + }) +}) +unlink(dummypackage, recursive = TRUE) + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") diff --git a/man/sepuku.Rd b/man/sepuku.Rd index 8856e5ad..26d69a13 100644 --- a/man/sepuku.Rd +++ b/man/sepuku.Rd @@ -2,16 +2,122 @@ % Please edit documentation in R/sepuku.R \name{sepuku} \alias{sepuku} -\title{sepuku Title} +\title{Clean a package from fusen-related files and tags +This function will remove all the flat files and the fusen-related tags from the package. It will also remove the configuration file if it exists.} \usage{ sepuku(pkg = ".", force = FALSE) } +\arguments{ +\item{pkg}{Character. Path of the current package} + +\item{force}{logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE)} +} \value{ -1 +a cleaned package } \description{ -sepuku Title +Clean a package from fusen-related files and tags +This function will remove all the flat files and the fusen-related tags from the package. It will also remove the configuration file if it exists. } \examples{ +\dontrun{ sepuku() +# If you want to force the cleaning, you can use the force argument +sepuku(force = TRUE) + +# Example with a dummy package with a flat file +dummypackage <- tempfile("sepuku.example") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + dir.create(file.path(dummypackage, "dev")) + dir.create(file.path(dummypackage, "dev", "flat_history")) + + # We add 2 flat files in the package and inflate them + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + + dev_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat2.Rmd", + open = FALSE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + # We deprecate the first flat file, which will be moved to the flat_history folder + deprecate_flat_file( + file.path(dummypackage, "dev", "flat_flat1.Rmd") + ) + + # We create 2 flat files with the qmd extension + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.qmd")) + file.create(file.path(dummypackage, "dev", "flat_qmd.qmd")) + + sepuku(force = TRUE) + + # We check that the fusen configuration file has been deleted + file.exists( + file.path(dummypackage, "dev", "config_fusen.yaml") + ) + + # We check that all the flat files have been deleted + length( + list.files(file.path(dummypackage, "dev"), + pattern = "flat_.*\\\\.Rmd" + ) + ) + + length( + list.files(file.path(dummypackage, "dev"), + pattern = "flat_.*\\\\.qmd" + ) + ) + + + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "flat_.*\\\\.Rmd" + ) + ) + + + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "flat_.*\\\\.qmd" + ) + ) + + # We check that all the files with fusen tags have been cleaned + length(fusen:::find_files_with_fusen_tags(pkg = dummypackage)) +}) + +# Clean the temporary directory +unlink(dummypackage, recursive = TRUE) +} } diff --git a/tests/testthat/test-sepuku.R b/tests/testthat/test-sepuku.R index 437a0ff1..6fa92898 100644 --- a/tests/testthat/test-sepuku.R +++ b/tests/testthat/test-sepuku.R @@ -157,15 +157,6 @@ usethis::with_project(dummypackage, { overwrite = "yes" ) - # if (interactive()) { - # test_that("sepuku tells the users that files will be modified or deleted and that it is irreversible", { - # expect_message( - # sepuku(force = FALSE), - # "Some files are about to be deleted or modified. This operation is irreversible." - # ) - # }) - # } - expect_message( sepuku(force = TRUE), "The following files have been identified as containing fusen-related tags and will therefore be modified:\nR/flat1_rmd.R\nR/flat2_rmd.R\ntests/testthat/test-flat1_rmd.R\ntests/testthat/test-flat2_rmd.R\nvignettes/get-started-2.Rmd\nvignettes/get-started.Rmd" @@ -178,6 +169,43 @@ dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + test_that("sepuku informs the user than modifying / deleting files can not be undone if force = FALSE", { + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + + if (interactive()) { + test_that("sepuku tells the users that files will be modified or deleted and that it is irreversible", { + expect_message( + sepuku(force = FALSE), + "Some files are about to be deleted or modified. This operation is irreversible." + ) + }) + } + }) +}) +unlink(dummypackage, recursive = TRUE) + +dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") diff --git a/tests/testthat/test-sepuku_utils.R b/tests/testthat/test-sepuku_utils.R index 0144b5e3..3a0ecda1 100644 --- a/tests/testthat/test-sepuku_utils.R +++ b/tests/testthat/test-sepuku_utils.R @@ -326,27 +326,29 @@ test_that("clean_fusen_tags_in_files is a function", { dummypackage <- tempfile(paste0(sample(letters, 10), collapse = "")) dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) -dev_file1 <- add_minimal_flat( - pkg = dummypackage, - flat_name = "flat1.Rmd", - open = FALSE, - overwrite = TRUE -) -inflate( - pkg = dummypackage, - flat_file = dev_file1, - vignette_name = "Get started", - check = FALSE, - open_vignette = FALSE, - document = TRUE, - overwrite = "yes" -) -files_with_fusen_tags <- find_files_with_fusen_tags(pkg = dummypackage) - usethis::with_project(dummypackage, { # Add licence usethis::use_mit_license("John Doe") + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE, + overwrite = TRUE + ) + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + files_with_fusen_tags <- find_files_with_fusen_tags(pkg = dummypackage) + + + test_that("clean_fusen_tags_in_files works with an empty pkg", { cleaned_files <- clean_fusen_tags_in_files(pkg = dummypackage, files_to_clean = files_with_fusen_tags) cleaned_files_with_fusen_tags <- find_files_with_fusen_tags() From e444d965c189715ef4a625f120951b6c37c91d57 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Fri, 7 Jun 2024 10:47:41 +0200 Subject: [PATCH 13/19] fix: Detecting flat files starting with flat Removing the flat_ pattern #257 --- R/sepuku.R | 8 ++++---- R/sepuku_utils.R | 4 ++-- dev/config_fusen.yaml | 1 + dev/flat_sepuku-utils.Rmd | 4 ++-- dev/flat_sepuku.Rmd | 16 ++++++++-------- man/sepuku.Rd | 8 ++++---- tests/testthat/test-sepuku.R | 8 ++++---- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/R/sepuku.R b/R/sepuku.R index d24217e5..afef939e 100644 --- a/R/sepuku.R +++ b/R/sepuku.R @@ -77,27 +77,27 @@ #' # We check that all the flat files have been deleted #' length( #' list.files(file.path(dummypackage, "dev"), -#' pattern = "flat_.*\\.Rmd" +#' pattern = "flat.*\\.Rmd" #' ) #' ) #' #' length( #' list.files(file.path(dummypackage, "dev"), -#' pattern = "flat_.*\\.qmd" +#' pattern = "^flat.*\\.qmd" #' ) #' ) #' #' #' length( #' list.files(file.path(dummypackage, "dev", "flat_history"), -#' pattern = "flat_.*\\.Rmd" +#' pattern = "flat.*\\.Rmd" #' ) #' ) #' #' #' length( #' list.files(file.path(dummypackage, "dev", "flat_history"), -#' pattern = "flat_.*\\.qmd" +#' pattern = "^flat.*\\.qmd" #' ) #' ) #' diff --git a/R/sepuku_utils.R b/R/sepuku_utils.R index 2500e5b2..3cfedd0d 100644 --- a/R/sepuku_utils.R +++ b/R/sepuku_utils.R @@ -28,12 +28,12 @@ list_flat_files_in_dev_folder <- function( c( list.files( path = file.path(pkg, folder), - pattern = "flat_.*\\.Rmd", + pattern = "^flat.*\\.Rmd", full.names = FALSE ), list.files( path = file.path(pkg, folder), - pattern = "flat_.*\\.qmd", + pattern = "^flat.*\\.qmd", full.names = FALSE ) ) diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index dcf11228..05a3e207 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -167,6 +167,7 @@ flat_sepuku-utils.Rmd: check: false document: true overwrite: 'yes' + clean: ask keep: path: keep state: active diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index 2c314fe1..2f1bc23c 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -123,12 +123,12 @@ list_flat_files_in_dev_folder <- function( c( list.files( path = file.path(pkg, folder), - pattern = "flat_.*\\.Rmd", + pattern = "^flat.*\\.Rmd", full.names = FALSE ), list.files( path = file.path(pkg, folder), - pattern = "flat_.*\\.qmd", + pattern = "^flat.*\\.qmd", full.names = FALSE ) ) diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index d22221ca..c4f85f79 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -188,27 +188,27 @@ usethis::with_project(dummypackage, { # We check that all the flat files have been deleted length( list.files(file.path(dummypackage, "dev"), - pattern = "flat_.*\\.Rmd" + pattern = "flat.*\\.Rmd" ) ) length( list.files(file.path(dummypackage, "dev"), - pattern = "flat_.*\\.qmd" + pattern = "^flat.*\\.qmd" ) ) length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat_.*\\.Rmd" + pattern = "flat.*\\.Rmd" ) ) length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat_.*\\.qmd" + pattern = "^flat.*\\.qmd" ) ) @@ -487,7 +487,7 @@ usethis::with_project(dummypackage, { expect_equal( length( list.files(file.path(dummypackage, "dev"), - pattern = "flat_.*\\.Rmd" + pattern = "flat.*\\.Rmd" ) ), 0 @@ -496,7 +496,7 @@ usethis::with_project(dummypackage, { expect_equal( length( list.files(file.path(dummypackage, "dev"), - pattern = "flat_.*\\.qmd" + pattern = "^flat.*\\.qmd" ) ), 0 @@ -505,7 +505,7 @@ usethis::with_project(dummypackage, { expect_equal( length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat_.*\\.Rmd" + pattern = "flat.*\\.Rmd" ) ), 0 @@ -514,7 +514,7 @@ usethis::with_project(dummypackage, { expect_equal( length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat_.*\\.qmd" + pattern = "^flat.*\\.qmd" ) ), 0 diff --git a/man/sepuku.Rd b/man/sepuku.Rd index 26d69a13..cfc04d28 100644 --- a/man/sepuku.Rd +++ b/man/sepuku.Rd @@ -89,27 +89,27 @@ usethis::with_project(dummypackage, { # We check that all the flat files have been deleted length( list.files(file.path(dummypackage, "dev"), - pattern = "flat_.*\\\\.Rmd" + pattern = "flat.*\\\\.Rmd" ) ) length( list.files(file.path(dummypackage, "dev"), - pattern = "flat_.*\\\\.qmd" + pattern = "^flat.*\\\\.qmd" ) ) length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat_.*\\\\.Rmd" + pattern = "flat.*\\\\.Rmd" ) ) length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat_.*\\\\.qmd" + pattern = "^flat.*\\\\.qmd" ) ) diff --git a/tests/testthat/test-sepuku.R b/tests/testthat/test-sepuku.R index 6fa92898..1de2986d 100644 --- a/tests/testthat/test-sepuku.R +++ b/tests/testthat/test-sepuku.R @@ -262,7 +262,7 @@ usethis::with_project(dummypackage, { expect_equal( length( list.files(file.path(dummypackage, "dev"), - pattern = "flat_.*\\.Rmd" + pattern = "flat.*\\.Rmd" ) ), 0 @@ -271,7 +271,7 @@ usethis::with_project(dummypackage, { expect_equal( length( list.files(file.path(dummypackage, "dev"), - pattern = "flat_.*\\.qmd" + pattern = "^flat.*\\.qmd" ) ), 0 @@ -280,7 +280,7 @@ usethis::with_project(dummypackage, { expect_equal( length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat_.*\\.Rmd" + pattern = "flat.*\\.Rmd" ) ), 0 @@ -289,7 +289,7 @@ usethis::with_project(dummypackage, { expect_equal( length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat_.*\\.qmd" + pattern = "^flat.*\\.qmd" ) ), 0 From c8dcd92b66152cb5b3688ce8667b4c288ba4f33e Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Fri, 7 Jun 2024 10:50:45 +0200 Subject: [PATCH 14/19] doc: completing sepuku() documentation #257 --- R/sepuku.R | 7 ++++--- dev/flat_sepuku.Rmd | 7 ++++--- man/sepuku.Rd | 10 ++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/sepuku.R b/R/sepuku.R index afef939e..e872e0e0 100644 --- a/R/sepuku.R +++ b/R/sepuku.R @@ -1,7 +1,8 @@ # WARNING - Generated by {fusen} from dev/flat_sepuku.Rmd: do not edit by hand #' Clean a package from fusen-related files and tags -#' This function will remove all the flat files and the fusen-related tags from the package. It will also remove the configuration file if it exists. +#' +#' This function will deleted all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folder). It will also remove the fusen-related tags added by calls to `fusen::inflate()` in files located in the "R/", "tests/" and "vignettes/" folders. It will also remove the configuration file if it exists. #' #' @param pkg Character. Path of the current package #' @param force logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE) @@ -77,7 +78,7 @@ #' # We check that all the flat files have been deleted #' length( #' list.files(file.path(dummypackage, "dev"), -#' pattern = "flat.*\\.Rmd" +#' pattern = "^flat.*\\.Rmd" #' ) #' ) #' @@ -90,7 +91,7 @@ #' #' length( #' list.files(file.path(dummypackage, "dev", "flat_history"), -#' pattern = "flat.*\\.Rmd" +#' pattern = "^flat.*\\.Rmd" #' ) #' ) #' diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index c4f85f79..a50c8565 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -18,7 +18,8 @@ pkgload::load_all(export_all = FALSE) ```{r function-sepuku} #' Clean a package from fusen-related files and tags -#' This function will remove all the flat files and the fusen-related tags from the package. It will also remove the configuration file if it exists. +#' +#' This function will deleted all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folder). It will also remove the fusen-related tags added by calls to `fusen::inflate()` in files located in the "R/", "tests/" and "vignettes/" folders. It will also remove the configuration file if it exists. #' #' @param pkg Character. Path of the current package #' @param force logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE) @@ -188,7 +189,7 @@ usethis::with_project(dummypackage, { # We check that all the flat files have been deleted length( list.files(file.path(dummypackage, "dev"), - pattern = "flat.*\\.Rmd" + pattern = "^flat.*\\.Rmd" ) ) @@ -201,7 +202,7 @@ usethis::with_project(dummypackage, { length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat.*\\.Rmd" + pattern = "^flat.*\\.Rmd" ) ) diff --git a/man/sepuku.Rd b/man/sepuku.Rd index cfc04d28..5bf08e3a 100644 --- a/man/sepuku.Rd +++ b/man/sepuku.Rd @@ -2,8 +2,7 @@ % Please edit documentation in R/sepuku.R \name{sepuku} \alias{sepuku} -\title{Clean a package from fusen-related files and tags -This function will remove all the flat files and the fusen-related tags from the package. It will also remove the configuration file if it exists.} +\title{Clean a package from fusen-related files and tags} \usage{ sepuku(pkg = ".", force = FALSE) } @@ -16,8 +15,7 @@ sepuku(pkg = ".", force = FALSE) a cleaned package } \description{ -Clean a package from fusen-related files and tags -This function will remove all the flat files and the fusen-related tags from the package. It will also remove the configuration file if it exists. +This function will deleted all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folder). It will also remove the fusen-related tags added by calls to \code{fusen::inflate()} in files located in the "R/", "tests/" and "vignettes/" folders. It will also remove the configuration file if it exists. } \examples{ \dontrun{ @@ -89,7 +87,7 @@ usethis::with_project(dummypackage, { # We check that all the flat files have been deleted length( list.files(file.path(dummypackage, "dev"), - pattern = "flat.*\\\\.Rmd" + pattern = "^flat.*\\\\.Rmd" ) ) @@ -102,7 +100,7 @@ usethis::with_project(dummypackage, { length( list.files(file.path(dummypackage, "dev", "flat_history"), - pattern = "flat.*\\\\.Rmd" + pattern = "^flat.*\\\\.Rmd" ) ) From 8f44b7250aba23fd22ff0e6c52ea0964544bec3e Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Mon, 10 Jun 2024 08:32:04 +0200 Subject: [PATCH 15/19] feat: Use more specific regexp to detect fusen tags in R files and vignettes #257 --- R/sepuku_utils.R | 5 +++++ dev/flat_sepuku-utils.Rmd | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/R/sepuku_utils.R b/R/sepuku_utils.R index 3cfedd0d..5e1c6ee7 100644 --- a/R/sepuku_utils.R +++ b/R/sepuku_utils.R @@ -136,6 +136,11 @@ clean_fusen_tags_in_files <- function( fusen_tags <- tolower( c("WARNING - Generated by", "Previously generated by", "WARNING - This vignette is generated by") ) + fusen_tags <- tolower(c( + "WARNING - Generated by.*do not edit by hand", + "Previously generated by.*now deprecated", + "This vignette is generated by.*do not edit by hand" + )) for (file in files_to_clean) { lines <- readLines(file.path(pkg, file)) diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index 2f1bc23c..b7da640a 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -506,6 +506,11 @@ clean_fusen_tags_in_files <- function( fusen_tags <- tolower( c("WARNING - Generated by", "Previously generated by", "WARNING - This vignette is generated by") ) + fusen_tags <- tolower(c( + "WARNING - Generated by.*do not edit by hand", + "Previously generated by.*now deprecated", + "This vignette is generated by.*do not edit by hand" + )) for (file in files_to_clean) { lines <- readLines(file.path(pkg, file)) From 0c48350d83683db85b1f46193b60d5799f70d52c Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Mon, 10 Jun 2024 09:22:25 +0200 Subject: [PATCH 16/19] doc: sepuku doc and fusen vignette #257 --- NAMESPACE | 1 + R/sepuku.R | 23 +-- dev/config_fusen.yaml | 4 +- dev/flat_sepuku.Rmd | 34 +++-- man/sepuku.Rd | 4 +- ...oped-with-fusen-to-a-classical-package.Rmd | 143 ++++++++++++++++++ 6 files changed, 181 insertions(+), 28 deletions(-) create mode 100644 vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd diff --git a/NAMESPACE b/NAMESPACE index 0483ff67..cf88ce9b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,6 +26,7 @@ export(rename_flat_file) export(sepuku) importFrom(attachment,att_amend_desc) importFrom(cli,cat_rule) +importFrom(cli,cli_abort) importFrom(cli,cli_alert_danger) importFrom(cli,cli_alert_info) importFrom(cli,cli_alert_success) diff --git a/R/sepuku.R b/R/sepuku.R index e872e0e0..c31a5688 100644 --- a/R/sepuku.R +++ b/R/sepuku.R @@ -2,11 +2,12 @@ #' Clean a package from fusen-related files and tags #' -#' This function will deleted all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folder). It will also remove the fusen-related tags added by calls to `fusen::inflate()` in files located in the "R/", "tests/" and "vignettes/" folders. It will also remove the configuration file if it exists. +#' This function will delete all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folders). It will also remove the fusen-related tags added by calls to `fusen::inflate()` in files located in the "R/", "tests/" and "vignettes/" folders. Finally, it will also remove the fusen configuration file if it exists. #' #' @param pkg Character. Path of the current package #' @param force logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE) -#' @return a cleaned package +#' @return side effect. A package cleaned from fusen-related files or tags +#' @importFrom cli cli_alert_info cli_alert_danger cli_abort cli_alert_success #' @export #' @examples #' \dontrun{ @@ -113,23 +114,23 @@ sepuku <- function( pkg = ".", force = FALSE) { if (!dir.exists(file.path(pkg, "dev"))) { - cli::cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") + cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") } config_file <- getOption("fusen.config_file", default = "dev/config_fusen.yaml") if (!file.exists(config_file)) { - cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") + cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") } else { - cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted.") + cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted.") } flat_files <- list_flat_files(pkg = pkg) if (length(flat_files) == 0) { - cli::cli_alert_info("No flat files were detected.") + cli_alert_info("No flat files were detected.") } else { - cli::cli_alert_info( + cli_alert_info( paste0( "The following flat files were detected and will therefore be deleted from your package:\n", paste0(flat_files, collapse = "\n") @@ -139,9 +140,9 @@ sepuku <- function( files_to_be_modified <- find_files_with_fusen_tags(pkg = pkg) if (length(files_to_be_modified) == 0) { - cli::cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.") + cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.") } else { - cli::cli_alert_info( + cli_alert_info( paste0( "The following files have been identified as containing fusen-related tags and will therefore be modified:\n", paste0(files_to_be_modified, collapse = "\n") @@ -156,7 +157,7 @@ sepuku <- function( do_it <- force if (!force) { - cli::cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") + cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") sure <- paste( "\nAre you sure of what you are doing? (y/n)\n" ) @@ -197,7 +198,7 @@ sepuku <- function( } } - cli::cli_alert_info("Cleaning is done !") + cli_alert_success("Cleaning is done !") return(invisible(TRUE)) } diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index 05a3e207..def6e5f5 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -145,10 +145,10 @@ flat_sepuku.Rmd: state: active R: R/sepuku.R tests: tests/testthat/test-sepuku.R - vignettes: [] + vignettes: vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd inflate: flat_file: dev/flat_sepuku.Rmd - vignette_name: .na + vignette_name: Switch from a package developed with fusen to a classical package open_vignette: false check: false document: true diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index a50c8565..28486340 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -14,38 +14,46 @@ library(testthat) pkgload::load_all(export_all = FALSE) ``` -# sepuku +# Move from a package developed with fusen to a "classical" package + +After a while, you may want to move from a package developed with fusen to a "classical" package. This is possible with the `sepuku()` function. This function will delete all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folders). It will also remove the fusen-related tags added by calls to `fusen::inflate()` in files located in the "R/", "tests/" and "vignettes/" folders. Finally, it will also remove the fusen configuration file if it exists. + +Switching from a package developed with fusen to a "classical" package might be useful if you want to share your package with someone who is not familiar with fusen or if you want to stop using fusen for any reason. + +Please be aware that this operation is irreversible. You will lose all the history of your flat files and the fusen-related tags in your package. Therefore, it is recommended to use code versioning to be able to revert this, in case you would change your mind. + ```{r function-sepuku} #' Clean a package from fusen-related files and tags #' -#' This function will deleted all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folder). It will also remove the fusen-related tags added by calls to `fusen::inflate()` in files located in the "R/", "tests/" and "vignettes/" folders. It will also remove the configuration file if it exists. +#' This function will delete all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folders). It will also remove the fusen-related tags added by calls to `fusen::inflate()` in files located in the "R/", "tests/" and "vignettes/" folders. Finally, it will also remove the fusen configuration file if it exists. #' #' @param pkg Character. Path of the current package #' @param force logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE) -#' @return a cleaned package +#' @return side effect. A package cleaned from fusen-related files or tags +#' @importFrom cli cli_alert_info cli_alert_danger cli_abort cli_alert_success #' @export sepuku <- function( pkg = ".", force = FALSE) { if (!dir.exists(file.path(pkg, "dev"))) { - cli::cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") + cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") } config_file <- getOption("fusen.config_file", default = "dev/config_fusen.yaml") if (!file.exists(config_file)) { - cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") + cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") } else { - cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted.") + cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted.") } flat_files <- list_flat_files(pkg = pkg) if (length(flat_files) == 0) { - cli::cli_alert_info("No flat files were detected.") + cli_alert_info("No flat files were detected.") } else { - cli::cli_alert_info( + cli_alert_info( paste0( "The following flat files were detected and will therefore be deleted from your package:\n", paste0(flat_files, collapse = "\n") @@ -55,9 +63,9 @@ sepuku <- function( files_to_be_modified <- find_files_with_fusen_tags(pkg = pkg) if (length(files_to_be_modified) == 0) { - cli::cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.") + cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.") } else { - cli::cli_alert_info( + cli_alert_info( paste0( "The following files have been identified as containing fusen-related tags and will therefore be modified:\n", paste0(files_to_be_modified, collapse = "\n") @@ -72,7 +80,7 @@ sepuku <- function( do_it <- force if (!force) { - cli::cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") + cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") sure <- paste( "\nAre you sure of what you are doing? (y/n)\n" ) @@ -113,7 +121,7 @@ sepuku <- function( } } - cli::cli_alert_info("Cleaning is done !") + cli_alert_success("Cleaning is done !") return(invisible(TRUE)) } @@ -534,7 +542,7 @@ usethis::with_project(dummypackage, { # Execute in the console directly fusen::inflate( flat_file = "dev/flat_sepuku.Rmd", - vignette_name = NA, + vignette_name = "Switch from a package developed with fusen to a classical package", check = FALSE, overwrite = TRUE, open_vignette = FALSE diff --git a/man/sepuku.Rd b/man/sepuku.Rd index 5bf08e3a..98de9062 100644 --- a/man/sepuku.Rd +++ b/man/sepuku.Rd @@ -12,10 +12,10 @@ sepuku(pkg = ".", force = FALSE) \item{force}{logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE)} } \value{ -a cleaned package +side effect. A package cleaned from fusen-related files or tags } \description{ -This function will deleted all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folder). It will also remove the fusen-related tags added by calls to \code{fusen::inflate()} in files located in the "R/", "tests/" and "vignettes/" folders. It will also remove the configuration file if it exists. +This function will delete all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folders). It will also remove the fusen-related tags added by calls to \code{fusen::inflate()} in files located in the "R/", "tests/" and "vignettes/" folders. Finally, it will also remove the fusen configuration file if it exists. } \examples{ \dontrun{ diff --git a/vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd b/vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd new file mode 100644 index 00000000..4d70e17c --- /dev/null +++ b/vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd @@ -0,0 +1,143 @@ +--- +title: "Switch from a package developed with fusen to a classical package" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Switch from a package developed with fusen to a classical package} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r} +library(fusen) +``` + + + + + + +# Move from a package developed with fusen to a "classical" package + +After a while, you may want to move from a package developed with fusen to a "classical" package. This is possible with the `sepuku()` function. This function will delete all the flat files (i.e files listed in the fusen configuration file, as well as rmd or qmd files starting with "flat" in the "dev/" and "dev/flat_history" folders). It will also remove the fusen-related tags added by calls to `fusen::inflate()` in files located in the "R/", "tests/" and "vignettes/" folders. Finally, it will also remove the fusen configuration file if it exists. + +Switching from a package developed with fusen to a "classical" package might be useful if you want to share your package with someone who is not familiar with fusen or if you want to stop using fusen for any reason. + +Please be aware that this operation is irreversible. You will lose all the history of your flat files and the fusen-related tags in your package. Therefore, it is recommended to use code versioning to be able to revert this, in case you would change your mind. + + +```{r examples-sepuku} +#| eval: no + +#' \dontrun{ +sepuku() +# If you want to force the cleaning, you can use the force argument +sepuku(force = TRUE) + +# Example with a dummy package with a flat file +dummypackage <- tempfile("sepuku.example") +dir.create(dummypackage) +fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) + +usethis::with_project(dummypackage, { + # Add licence + usethis::use_mit_license("John Doe") + + dir.create(file.path(dummypackage, "dev")) + dir.create(file.path(dummypackage, "dev", "flat_history")) + + # We add 2 flat files in the package and inflate them + dev_file1 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat1.Rmd", + open = FALSE + ) + + dev_file2 <- add_minimal_flat( + pkg = dummypackage, + flat_name = "flat2.Rmd", + open = FALSE + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file1, + vignette_name = "Get started", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + inflate( + pkg = dummypackage, + flat_file = dev_file2, + vignette_name = "Get started 2", + check = FALSE, + open_vignette = FALSE, + document = TRUE, + overwrite = "yes" + ) + + # We deprecate the first flat file, which will be moved to the flat_history folder + deprecate_flat_file( + file.path(dummypackage, "dev", "flat_flat1.Rmd") + ) + + # We create 2 flat files with the qmd extension + file.create(file.path(dummypackage, "dev", "flat_history", "flat_old.qmd")) + file.create(file.path(dummypackage, "dev", "flat_qmd.qmd")) + + sepuku(force = TRUE) + + # We check that the fusen configuration file has been deleted + file.exists( + file.path(dummypackage, "dev", "config_fusen.yaml") + ) + + # We check that all the flat files have been deleted + length( + list.files(file.path(dummypackage, "dev"), + pattern = "^flat.*\\.Rmd" + ) + ) + + length( + list.files(file.path(dummypackage, "dev"), + pattern = "^flat.*\\.qmd" + ) + ) + + + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "^flat.*\\.Rmd" + ) + ) + + + length( + list.files(file.path(dummypackage, "dev", "flat_history"), + pattern = "^flat.*\\.qmd" + ) + ) + + # We check that all the files with fusen tags have been cleaned + length(fusen:::find_files_with_fusen_tags(pkg = dummypackage)) +}) + +# Clean the temporary directory +unlink(dummypackage, recursive = TRUE) +#' } +``` + + + + + From 715f8a88e8309453de58eb2475b6c0cbc2d3af46 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Mon, 10 Jun 2024 10:04:24 +0200 Subject: [PATCH 17/19] fix: Fixing bugs in sepuku - The user was asked to confirm sepuku twice - The flat_history folder was not deleted - The message telling cleaning was done was displayed even if the cleaning was cancelled #257 --- R/sepuku.R | 24 ++++++++++++++++-------- dev/flat_sepuku.Rmd | 24 ++++++++++++++++-------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/R/sepuku.R b/R/sepuku.R index c31a5688..2a3853e4 100644 --- a/R/sepuku.R +++ b/R/sepuku.R @@ -158,13 +158,12 @@ sepuku <- function( if (!force) { cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") - sure <- paste( - "\nAre you sure of what you are doing? (y/n)\n" + clean <- readline( + prompt = "Are you sure of what you are doing? (y/n)" ) - clean <- readline(sure) == "y" || readline(sure) == "yes" - if (isTRUE(clean) || clean == "yes") { + if (tolower(clean) %in% c("yes", "y")) { do_it <- TRUE - } else if (isFALSE(clean) || clean == "no") { + } else if (tolower(clean) %in% c("no", "n")) { do_it <- FALSE } else { stop("clean should be TRUE, FALSE, 'yes'or 'no'") @@ -181,6 +180,17 @@ sepuku <- function( } ) ) + try( + unlink( + file.path( + pkg, + "dev", + "flat_history" + ), + recursive = TRUE + ), + silent = TRUE + ) } if (length(files_to_be_modified) > 0) { @@ -196,9 +206,7 @@ sepuku <- function( if (file.exists(config_file)) { file.remove(config_file) } + cli_alert_success("Cleaning is done !") } - - cli_alert_success("Cleaning is done !") - return(invisible(TRUE)) } diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index 28486340..6f9e6967 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -81,13 +81,12 @@ sepuku <- function( if (!force) { cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") - sure <- paste( - "\nAre you sure of what you are doing? (y/n)\n" + clean <- readline( + prompt = "Are you sure of what you are doing? (y/n)" ) - clean <- readline(sure) == "y" || readline(sure) == "yes" - if (isTRUE(clean) || clean == "yes") { + if (tolower(clean) %in% c("yes", "y")) { do_it <- TRUE - } else if (isFALSE(clean) || clean == "no") { + } else if (tolower(clean) %in% c("no", "n")) { do_it <- FALSE } else { stop("clean should be TRUE, FALSE, 'yes'or 'no'") @@ -104,6 +103,17 @@ sepuku <- function( } ) ) + try( + unlink( + file.path( + pkg, + "dev", + "flat_history" + ), + recursive = TRUE + ), + silent = TRUE + ) } if (length(files_to_be_modified) > 0) { @@ -119,10 +129,8 @@ sepuku <- function( if (file.exists(config_file)) { file.remove(config_file) } + cli_alert_success("Cleaning is done !") } - - cli_alert_success("Cleaning is done !") - return(invisible(TRUE)) } ``` From 053c69420be02fac0db0289b595f935a0ee7a121 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Mon, 10 Jun 2024 10:07:54 +0200 Subject: [PATCH 18/19] chore: v0.6.0.9001 sepuku() #257 #260 --- DESCRIPTION | 2 +- NEWS.md | 137 ++++++++++++++++++++++++++-------------------------- 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 54e8379f..831a2dd9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fusen Title: Build a Package from Rmarkdown Files -Version: 0.6.0.9000 +Version: 0.6.0.9001 Authors@R: c( person("Sebastien", "Rochette", , "sebastienrochettefr@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-1565-9313")), diff --git a/NEWS.md b/NEWS.md index 755b59d7..2744169a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# fusen (development) +# fusen (development version 0.6.0.9001) + +## New features + +- Adding `sepuku()`, allowing to remove all traces of a fusen-related files and tags in the package (#257 #258 #259) @ymansiaux # fusen 0.6.0 @@ -10,10 +14,10 @@ ## New features - `draw_package_structure()` along with `get_package_structure()` allows to draw the package structure with -all functions created in each R file, and whether they are exported (#189) + all functions created in each R file, and whether they are exported (#189) - `rename_flat_file()` allows to rename a flat file, and deals with config and inflated files - `deprecate_flat_file()` helps properly deprecate a flat file, modifies the config file -and cleans the previously inflated files + and cleans the previously inflated files - `inflate()` detects functions renamed or removed and allow to clean the package repository (#24) - Allow `organisation` in `init_share_on_github()` to send to a GitHub organisation - Fix `load_flat_functions()` to work with VSCode @@ -68,8 +72,6 @@ and cleans the previously inflated files - `create_fusen()` vaccinates created git project (#171) - Examples under function roxygen documentation are cleaned from extra spaces after empty `#'` to avoid git diff against code linters / stylers. - - # fusen 0.5.0 ## New features @@ -113,112 +115,111 @@ and cleans the previously inflated files ## New features -* `inflate()` the current opened flat file if `flat_file` is empty (#138) -* Add rmarkdown template for additional flat file for RStudio -* Add wrappers around `add_flat_template()` for lazy devs: `add_additional()`, `add_full()`, `add_minimal()` -* Show "flat_template" origin of files generated by {fusen} (@ -ALanguillaume) -* Allow `inflate(vignette_name = c("Super title" = "01-Super Slug"))` for nice Title different from vignette Entry (#87) -* Get the author and date from flat file to the vignette (#129) +- `inflate()` the current opened flat file if `flat_file` is empty (#138) +- Add rmarkdown template for additional flat file for RStudio +- Add wrappers around `add_flat_template()` for lazy devs: `add_additional()`, `add_full()`, `add_minimal()` +- Show "flat_template" origin of files generated by {fusen} (@ + ALanguillaume) +- Allow `inflate(vignette_name = c("Super title" = "01-Super Slug"))` for nice Title different from vignette Entry (#87) +- Get the author and date from flat file to the vignette (#129) ## Bug fixes -* Read DESCRIPTION file for package name when available (#144 @VincentGuyader) -* Read `nyc_squirrels` with encoding to avoid encoding problems with `use_data()` -* Allow flat files with `tests` only -* Extract yaml metadata from flat file, like author or date to include in the inflated vignette -* Simplify "flat_teaching" with a unique simple function -* Fix `asciify_name()` to account for diacritics (@ -ALanguillaume) -* Improve template 'full' for internal data use -* Fix tests when git does not exists +- Read DESCRIPTION file for package name when available (#144 @VincentGuyader) +- Read `nyc_squirrels` with encoding to avoid encoding problems with `use_data()` +- Allow flat files with `tests` only +- Extract yaml metadata from flat file, like author or date to include in the inflated vignette +- Simplify "flat_teaching" with a unique simple function +- Fix `asciify_name()` to account for diacritics (@ + ALanguillaume) +- Improve template 'full' for internal data use +- Fix tests when git does not exists # fusen 0.3.0 ## Breaking changes -* `add_flat_template()` superseeds `add_dev_history()` with more advanced possibilities -* `add_dev_history()` is deprecated -* Vignette name to create is now set with `inflate(vignette_name = "Get started")` instead of `name` -* Flat name to inflate is now set with `inflate(flat_file = "dev/flat_full.Rmd")` instead of `rmd` +- `add_flat_template()` superseeds `add_dev_history()` with more advanced possibilities +- `add_dev_history()` is deprecated +- Vignette name to create is now set with `inflate(vignette_name = "Get started")` instead of `name` +- Flat name to inflate is now set with `inflate(flat_file = "dev/flat_full.Rmd")` instead of `rmd` ## Major changes -* Check included now uses `devtools::check()` instead of `rcmdcheck()` -* Avoid creating vignette with `inflate(vignette_name = NA)` -* Decide whether or not to open vignette when inflate with `inflate(open_vignette = FALSE)` -* Improve documentation included in flat templates to reflect changes in using dev_history file -* Add RStudio Addin to insert a new flat template -* Add RStudio Addin to insert chunks for new function (@ColinFay) -* Deal with `\dontrun{}` in example chunks -* Allow short names for chunks: dev, fun, ex, test -* `create_fusen()` to create a {fusen} project from command line or with RStudio new project (@ALanguillaume) -* Add "do not edit by hand" in files generated +- Check included now uses `devtools::check()` instead of `rcmdcheck()` +- Avoid creating vignette with `inflate(vignette_name = NA)` +- Decide whether or not to open vignette when inflate with `inflate(open_vignette = FALSE)` +- Improve documentation included in flat templates to reflect changes in using dev_history file +- Add RStudio Addin to insert a new flat template +- Add RStudio Addin to insert chunks for new function (@ColinFay) +- Deal with `\dontrun{}` in example chunks +- Allow short names for chunks: dev, fun, ex, test +- `create_fusen()` to create a {fusen} project from command line or with RStudio new project (@ALanguillaume) +- Add "do not edit by hand" in files generated ### Grouping functions under the same file -* Group functions in same R file and test file if under same (level 1 + level 2) titles in the Rmd -* Group functions in same R file and test file if they have the same `@rdname` roxygen tag -* Group functions in same R file and test file if they have the same `@filename` roxygen tag (only recognized by 'fusen') -* Group functions in same R file and test file if the function chunk get chunk option `{r function-my_func, filename = "my_filename"}` - +- Group functions in same R file and test file if under same (level 1 + level 2) titles in the Rmd +- Group functions in same R file and test file if they have the same `@rdname` roxygen tag +- Group functions in same R file and test file if they have the same `@filename` roxygen tag (only recognized by 'fusen') +- Group functions in same R file and test file if the function chunk get chunk option `{r function-my_func, filename = "my_filename"}` ## Minor changes -* `add_flat_template()` uses the `flat_name` to pre-fill the template with the first function name. -* Fix .onLoad functions file creation -* Allow `R6Class()` in `function` chunks -* Fix inflate function chunks with data or package documentation only -* Fix inflate with empty functions chunks -* Fix filename to inflate in templates with new calls of `add_dev_history()` (@Cervangirard) -* Default vignette name is now "Get started" creating "vignettes/get-started.Rmd" -* All open files are saved when using `inflate()` where {RStudioapi} works -* Ask to restart RStudio after first inflate +- `add_flat_template()` uses the `flat_name` to pre-fill the template with the first function name. +- Fix .onLoad functions file creation +- Allow `R6Class()` in `function` chunks +- Fix inflate function chunks with data or package documentation only +- Fix inflate with empty functions chunks +- Fix filename to inflate in templates with new calls of `add_dev_history()` (@Cervangirard) +- Default vignette name is now "Get started" creating "vignettes/get-started.Rmd" +- All open files are saved when using `inflate()` where {RStudioapi} works +- Ask to restart RStudio after first inflate # fusen 0.2.4 -* Update vignette and tests +- Update vignette and tests # fusen 0.2.3 -* Update unit tests -* Show check outputs in console -* Ask before overwriting everything -* Check Description Title and description fields -* Check if folder name is correct package name +- Update unit tests +- Show check outputs in console +- Ask before overwriting everything +- Check Description Title and description fields +- Check if folder name is correct package name # fusen 0.2.2 -* Protect tests from older Pandoc versions +- Protect tests from older Pandoc versions # fusen 0.2.1 -* Fix documentation issues for CRAN -* Add templates for "dev_history.Rmd" file -* Add more informative messages to users -* New vignette to explain how to maintain a {fusen} package +- Fix documentation issues for CRAN +- Add templates for "dev_history.Rmd" file +- Add more informative messages to users +- New vignette to explain how to maintain a {fusen} package # fusen 0.2.0 -* Prepare for CRAN +- Prepare for CRAN # fusen 0.1.1 ## features -* Allow non-clean vignette name -* Allow different "dev_history" templates: "full", "minimal" and "additional" +- Allow non-clean vignette name +- Allow different "dev_history" templates: "full", "minimal" and "additional" ## documentation -* Add vignette to explain how to maintain a package with {fusen} -* Add vignette to explain how to deal with data -* Added a `NEWS.md` file to track changes to the package. +- Add vignette to explain how to maintain a package with {fusen} +- Add vignette to explain how to deal with data +- Added a `NEWS.md` file to track changes to the package. ## tests -* Add tests for corner cases in Rmd templates +- Add tests for corner cases in Rmd templates # fusen 0.1.0 -* First release +- First release From 117bba6d1276f56f37148921d5f21181dbf82683 Mon Sep 17 00:00:00 2001 From: Yohann Mansiaux Date: Mon, 10 Jun 2024 10:12:56 +0200 Subject: [PATCH 19/19] doc: Quick doc fix for sepuku() #257 --- R/sepuku.R | 2 +- dev/flat_sepuku.Rmd | 2 +- man/sepuku.Rd | 2 +- ...om-a-package-developed-with-fusen-to-a-classical-package.Rmd | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/sepuku.R b/R/sepuku.R index 2a3853e4..09f6e9c9 100644 --- a/R/sepuku.R +++ b/R/sepuku.R @@ -15,7 +15,7 @@ #' # If you want to force the cleaning, you can use the force argument #' sepuku(force = TRUE) #' -#' # Example with a dummy package with a flat file +#' # Example with a dummy package #' dummypackage <- tempfile("sepuku.example") #' dir.create(dummypackage) #' fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index 6f9e6967..4443089e 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -141,7 +141,7 @@ sepuku() # If you want to force the cleaning, you can use the force argument sepuku(force = TRUE) -# Example with a dummy package with a flat file +# Example with a dummy package dummypackage <- tempfile("sepuku.example") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) diff --git a/man/sepuku.Rd b/man/sepuku.Rd index 98de9062..89ec4974 100644 --- a/man/sepuku.Rd +++ b/man/sepuku.Rd @@ -23,7 +23,7 @@ sepuku() # If you want to force the cleaning, you can use the force argument sepuku(force = TRUE) -# Example with a dummy package with a flat file +# Example with a dummy package dummypackage <- tempfile("sepuku.example") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) diff --git a/vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd b/vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd index 4d70e17c..ca67e087 100644 --- a/vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd +++ b/vignettes/switch-from-a-package-developed-with-fusen-to-a-classical-package.Rmd @@ -40,7 +40,7 @@ sepuku() # If you want to force the cleaning, you can use the force argument sepuku(force = TRUE) -# Example with a dummy package with a flat file +# Example with a dummy package dummypackage <- tempfile("sepuku.example") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package"))