diff --git a/DESCRIPTION b/DESCRIPTION index 6561e404..23bdd399 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fusen Title: Build a Package from Rmarkdown Files -Version: 0.5.1 +Version: 0.5.2 Authors@R: c( person("Sebastien", "Rochette", , "sebastien@thinkr.fr", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-1565-9313")), @@ -47,10 +47,10 @@ Suggests: withr VignetteBuilder: knitr -Config/fusen/version: 0.5.1 +Config/fusen/version: 0.5.2 Config/Needs/website: ThinkR-open/thinkrtemplate Config/testthat/edition: 3 -Config/testthat/parallel: true +Config/testthat/parallel: false Encoding: UTF-8 Language: en-US LazyData: true diff --git a/R/add_flat_template.R b/R/add_flat_template.R index f54c0408..d1c8f98e 100644 --- a/R/add_flat_template.R +++ b/R/add_flat_template.R @@ -129,7 +129,7 @@ create_fusen_choices <- c("full", "minimal", "teaching", "dev_history") #' #' @examples #' # Create a new project -#' dummypackage <- tempfile("dummypackage") +#' dummypackage <- tempfile("dummy.package.flat") #' dir.create(dummypackage) #' #' # Add diff --git a/R/create_fusen_rsproject.R b/R/create_fusen_rsproject.R index 57d5048b..462aa861 100644 --- a/R/create_fusen_rsproject.R +++ b/R/create_fusen_rsproject.R @@ -125,7 +125,7 @@ create_fusen_gui <- function(path, flat_name = template, with_git) { create_fusen( - path = file.path(getwd(), path), + path = file.path(normalize_path_winslash(getwd()), path), template = template, flat_name = flat_name, open = FALSE, # Project opening is done spontaneously by Rstudio Project Wizard diff --git a/R/fill_description.R b/R/fill_description.R index 0883744f..57309fb0 100644 --- a/R/fill_description.R +++ b/R/fill_description.R @@ -12,7 +12,7 @@ #' #' @examples #' # Create a new project -#' dummypackage <- tempfile("dummypackage") +#' dummypackage <- tempfile("dummy.package.desc") #' dir.create(dummypackage) #' #' fill_description( diff --git a/R/inflate.R b/R/inflate.R index 285ccb80..5252e62f 100644 --- a/R/inflate.R +++ b/R/inflate.R @@ -42,7 +42,7 @@ regex_example <- paste(regex_example_vec, collapse = "|") #' #' @examples #' # Create a new project -#' dummypackage <- tempfile("dummypackage") +#' dummypackage <- tempfile("dummy.package") #' dir.create(dummypackage) #' #' # {fusen} steps @@ -127,11 +127,21 @@ inflate <- function(pkg = ".", flat_file, } old <- setwd(pkg) - on.exit(setwd(old)) + if (normalizePath(old, mustWork = FALSE) != normalizePath(pkg, mustWork = FALSE)) { + if (dir.exists(old)) { + on.exit(setwd(old)) + } else { + on.exit(here::here()) + } + } old_proj <- usethis::proj_get() - if (normalizePath(old_proj) != normalizePath(pkg)) { - on.exit(usethis::proj_set(old_proj)) + if (normalizePath(old_proj, mustWork = FALSE) != normalizePath(pkg, mustWork = FALSE)) { + if (dir.exists(old_proj)) { + on.exit(usethis::proj_set(old_proj)) + } else { + on.exit(usethis::proj_set(here::here())) + } usethis::proj_set(pkg) } diff --git a/R/inflate_all.R b/R/inflate_all.R index f4c01f89..b2813f8b 100644 --- a/R/inflate_all.R +++ b/R/inflate_all.R @@ -40,7 +40,7 @@ #' #' # You can also inflate_all flats of another package as follows #' # Example with a dummy package with a flat file -#' dummypackage <- tempfile("inflateall") +#' dummypackage <- tempfile("inflateall.otherpkg") #' dir.create(dummypackage) #' fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) #' flat_files <- add_minimal_package( diff --git a/R/register_config_file.R b/R/register_config_file.R index 6dfef179..fc090f1a 100644 --- a/R/register_config_file.R +++ b/R/register_config_file.R @@ -58,7 +58,7 @@ #' }) #' unlink(dummypackage, recursive = TRUE) check_not_registered_files <- function(path = ".", guess = TRUE, to_csv = TRUE, open = FALSE) { - path <- normalizePath(path, winslash = "/") + path <- normalize_path_winslash(path) all_r <- list.files(file.path(path, "R"), pattern = "[.]R$|[.]r$", full.names = TRUE) all_test <- list.files(file.path(path, "tests", "testthat"), pattern = "[.]R$|[.]r$", full.names = TRUE) @@ -86,7 +86,7 @@ check_not_registered_files <- function(path = ".", guess = TRUE, to_csv = TRUE, if (file.exists(config_file)) { # Read config file, and remove those already there config_list <- yaml::read_yaml(config_file) - config_list_path <- normalizePath(get_list_paths(config_list), mustWork = FALSE, winslash = "/") + config_list_path <- normalize_path_winslash(get_list_paths(config_list), mustWork = FALSE) res_existing <- res[res$path %in% config_list_path, ] res_new <- res[!res$path %in% config_list_path, ] config_flat_paths <- sapply(config_list, function(x) x[["path"]]) @@ -121,11 +121,11 @@ check_not_registered_files <- function(path = ".", guess = TRUE, to_csv = TRUE, } # TODO go back to relative path - res_new$path <- gsub(paste0(getwd(), "/"), "", normalize_path_winslash(res_new$path, mustWork = TRUE), fixed = TRUE) + res_new$path <- gsub(paste0(normalize_path_winslash(getwd()), "/"), "", normalize_path_winslash(res_new$path, mustWork = TRUE), fixed = TRUE) # config_file may not exist already csv_file <- file.path( - gsub(paste0(getwd(), "/"), "", dirname(normalize_path_winslash(config_file, mustWork = FALSE)), fixed = TRUE), "config_not_registered.csv" + gsub(paste0(normalize_path_winslash(getwd()), "/"), "", dirname(normalize_path_winslash(config_file, mustWork = FALSE)), fixed = TRUE), "config_not_registered.csv" ) # Save for manual modification @@ -174,9 +174,12 @@ guess_flat_origin <- function(path) { lines[grep("(G|g)enerated by \\{fusen\\} from", lines)][1] ) - guess_path <- normalizePath(guess_path, mustWork = FALSE, winslash = "/") + guess_path <- normalize_path_winslash(guess_path, mustWork = FALSE) if (file.exists(guess_path)) { - guess_path <- gsub(paste0(getwd(), "/"), "", normalizePath(guess_path, mustWork = FALSE, winslash = "/")) + guess_path <- gsub( + paste0(normalize_path_winslash(getwd()), "/"), "", + normalize_path_winslash(guess_path, mustWork = FALSE) + ) return(guess_path) } else { return("No existing source path found.") @@ -638,7 +641,7 @@ register_all_to_config <- function(pkg = ".") { # Delete out_df csv_file <- file.path( - gsub(paste0(getwd(), "/"), "", dirname(normalize_path_winslash(config_file, mustWork = FALSE)), fixed = TRUE), "config_not_registered.csv" + gsub(paste0(normalize_path_winslash(getwd()), "/"), "", dirname(normalize_path_winslash(config_file, mustWork = FALSE)), fixed = TRUE), "config_not_registered.csv" ) if (file.exists(csv_file)) { cli::cat_rule(paste("Delete", csv_file)) diff --git a/dev/dev_history.R b/dev/dev_history.R index 8df4867b..610c9bcb 100644 --- a/dev/dev_history.R +++ b/dev/dev_history.R @@ -194,6 +194,7 @@ testthat::test_file("tests/testthat/test-add_flat_template.R") testthat::test_file("tests/testthat/test-skeleton.R") Sys.setenv("NOT_CRAN" = "false") +# Run line by line Sys.setenv("FUSEN_TEST_PUBLISH" = "TRUE") testthat::test_file("tests/testthat/test-init_share_on_github.R") Sys.setenv("FUSEN_TEST_PUBLISH" = "FALSE") @@ -206,32 +207,6 @@ Sys.setenv("FUSEN_TEST_PUBLISH" = "FALSE") # Run examples in interactive mode too devtools::run_examples() -local <- utils::fileSnapshot(".", timestamp = tempfile("timestamp"), md5sum = TRUE) -home <- utils::fileSnapshot("~", timestamp = tempfile("timestamp"), md5sum = TRUE) - -# run tests or whatever, then ... -# x <- autotest::autotest_package(test = TRUE) -devtools::test() -devtools::run_examples() -# vignettes -dircheck <- tempfile("check") -dir.create(dircheck) -rcmdcheck::rcmdcheck(check_dir = dircheck) -# browseURL(dircheck) - -the_dir <- list.files(file.path(dircheck), pattern = ".Rcheck", full.names = TRUE) -# Same tests, no new files -all(list.files(file.path(the_dir, "tests", "testthat")) %in% - list.files(file.path(".", "tests", "testthat"))) - -devtools::build_vignettes() -devtools::clean_vignettes() - -utils::changedFiles(local, md5sum = TRUE) -utils::changedFiles(home, md5sum = TRUE) - -DT::datatable(x) - # Check package as CRAN rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran")) devtools::check(args = c("--no-manual", "--as-cran")) @@ -240,9 +215,12 @@ devtools::check(args = c("--no-manual", "--as-cran")) # remotes::install_github("ThinkR-open/checkhelper") tags <- checkhelper::find_missing_tags() View(tags$functions) + +# Remettre: Config/testthat/parallel: false dans DESCRIPTION out <- checkhelper::check_clean_userspace(pkg = ".") out checkhelper::check_as_cran() +# Remettre: Config/testthat/parallel: true dans DESCRIPTION # Check spelling # usethis::use_spell_check() @@ -260,7 +238,7 @@ usethis::use_version(which = c("patch", "minor", "major", "dev")[2]) # _rhub devtools::check_rhub() rhub::platforms() -rhub::check_on_windows(check_args = "--force-multiarch") +rhub::check_on_windows(check_args = "--force-multiarch", show_status = FALSE) rhub::check_on_solaris(show_status = FALSE) rhub::check(platform = "debian-clang-devel", show_status = FALSE) rhub::check(platform = "debian-gcc-devel", show_status = FALSE) diff --git a/dev/flat_create_flat.Rmd b/dev/flat_create_flat.Rmd index 3339bbe5..816e1b99 100644 --- a/dev/flat_create_flat.Rmd +++ b/dev/flat_create_flat.Rmd @@ -249,7 +249,7 @@ local_file_ignore <- function(file, ignores) { ```{r examples-1} # Create a new project -dummypackage <- tempfile("dummypackage") +dummypackage <- tempfile("dummy.package.flat") dir.create(dummypackage) # Add @@ -461,7 +461,7 @@ for (template in all_templates) { main_flat_file_name <- "teaching" } - dummypackage4 <- tempfile(pattern = "all.templates.knit") + dummypackage4 <- tempfile(pattern = paste0("all.templates.knit", gsub("_", ".", template))) dir.create(dummypackage4) orig.proj <- here::here() diff --git a/dev/flat_inflate_all.Rmd b/dev/flat_inflate_all.Rmd index 2147f89f..65b66139 100644 --- a/dev/flat_inflate_all.Rmd +++ b/dev/flat_inflate_all.Rmd @@ -194,7 +194,7 @@ inflate_all(stylers = styler::style_pkg) # You can also inflate_all flats of another package as follows # Example with a dummy package with a flat file -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.otherpkg") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) flat_files <- add_minimal_package( @@ -241,7 +241,7 @@ unlink(dummypackage, recursive = TRUE) ```{r tests-inflate_all} # unlink(dummypackage, recursive = TRUE) -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.first") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) dev_file <- suppressMessages(add_minimal_package(pkg = dummypackage, overwrite = TRUE, open = FALSE)) @@ -484,7 +484,7 @@ unlink(dummypackage, recursive = TRUE) # You can also inflate_all flats of another package as follows # Example with a dummy package with a flat file -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.other.pkg") dir.create(dummypackage) suppressMessages(fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package"))) flat_files <- add_minimal_package( @@ -540,7 +540,7 @@ usethis::with_project(dummypackage, { unlink(dummypackage, recursive = TRUE) # Test inflate_all_no_check vs inflate_all with check ---- -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.nocheck") dir.create(dummypackage) suppressMessages(fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package"))) dev_file <- suppressMessages(add_minimal_package(pkg = dummypackage, overwrite = TRUE, open = FALSE)) diff --git a/dev/flat_register_config_file.Rmd b/dev/flat_register_config_file.Rmd index 50a67cae..6381e7fd 100644 --- a/dev/flat_register_config_file.Rmd +++ b/dev/flat_register_config_file.Rmd @@ -154,7 +154,7 @@ Have a look at the configuration file at the end of the process to check that ev #' #' @export check_not_registered_files <- function(path = ".", guess = TRUE, to_csv = TRUE, open = FALSE) { - path <- normalizePath(path, winslash = "/") + path <- normalize_path_winslash(path) all_r <- list.files(file.path(path, "R"), pattern = "[.]R$|[.]r$", full.names = TRUE) all_test <- list.files(file.path(path, "tests", "testthat"), pattern = "[.]R$|[.]r$", full.names = TRUE) @@ -182,7 +182,7 @@ check_not_registered_files <- function(path = ".", guess = TRUE, to_csv = TRUE, if (file.exists(config_file)) { # Read config file, and remove those already there config_list <- yaml::read_yaml(config_file) - config_list_path <- normalizePath(get_list_paths(config_list), mustWork = FALSE, winslash = "/") + config_list_path <- normalize_path_winslash(get_list_paths(config_list), mustWork = FALSE) res_existing <- res[res$path %in% config_list_path, ] res_new <- res[!res$path %in% config_list_path, ] config_flat_paths <- sapply(config_list, function(x) x[["path"]]) @@ -217,11 +217,11 @@ check_not_registered_files <- function(path = ".", guess = TRUE, to_csv = TRUE, } # TODO go back to relative path - res_new$path <- gsub(paste0(getwd(), "/"), "", normalize_path_winslash(res_new$path, mustWork = TRUE), fixed = TRUE) + res_new$path <- gsub(paste0(normalize_path_winslash(getwd()), "/"), "", normalize_path_winslash(res_new$path, mustWork = TRUE), fixed = TRUE) # config_file may not exist already csv_file <- file.path( - gsub(paste0(getwd(), "/"), "", dirname(normalize_path_winslash(config_file, mustWork = FALSE)), fixed = TRUE), "config_not_registered.csv" + gsub(paste0(normalize_path_winslash(getwd()), "/"), "", dirname(normalize_path_winslash(config_file, mustWork = FALSE)), fixed = TRUE), "config_not_registered.csv" ) # Save for manual modification @@ -270,9 +270,12 @@ guess_flat_origin <- function(path) { lines[grep("(G|g)enerated by \\{fusen\\} from", lines)][1] ) - guess_path <- normalizePath(guess_path, mustWork = FALSE, winslash = "/") + guess_path <- normalize_path_winslash(guess_path, mustWork = FALSE) if (file.exists(guess_path)) { - guess_path <- gsub(paste0(getwd(), "/"), "", normalizePath(guess_path, mustWork = FALSE, winslash = "/")) + guess_path <- gsub( + paste0(normalize_path_winslash(getwd()), "/"), "", + normalize_path_winslash(guess_path, mustWork = FALSE) + ) return(guess_path) } else { return("No existing source path found.") @@ -521,7 +524,7 @@ register_all_to_config <- function(pkg = ".") { # Delete out_df csv_file <- file.path( - gsub(paste0(getwd(), "/"), "", dirname(normalize_path_winslash(config_file, mustWork = FALSE)), fixed = TRUE), "config_not_registered.csv" + gsub(paste0(normalize_path_winslash(getwd()), "/"), "", dirname(normalize_path_winslash(config_file, mustWork = FALSE)), fixed = TRUE), "config_not_registered.csv" ) if (file.exists(csv_file)) { cli::cat_rule(paste("Delete", csv_file)) diff --git a/man/add_flat_template.Rd b/man/add_flat_template.Rd index dc16404b..fdff1ece 100644 --- a/man/add_flat_template.Rd +++ b/man/add_flat_template.Rd @@ -93,7 +93,7 @@ Abbreviated names can also be used for the different templates: } \examples{ # Create a new project -dummypackage <- tempfile("dummypackage") +dummypackage <- tempfile("dummy.package.flat") dir.create(dummypackage) # Add diff --git a/man/fill_description.Rd b/man/fill_description.Rd index 9e1fdb8c..309d5b40 100644 --- a/man/fill_description.Rd +++ b/man/fill_description.Rd @@ -23,7 +23,7 @@ Fill DESCRIPTION file of the package } \examples{ # Create a new project -dummypackage <- tempfile("dummypackage") +dummypackage <- tempfile("dummy.package.desc") dir.create(dummypackage) fill_description( diff --git a/man/inflate.Rd b/man/inflate.Rd index 7c28d550..a1159f3f 100644 --- a/man/inflate.Rd +++ b/man/inflate.Rd @@ -44,7 +44,7 @@ Inflate Rmd to package } \examples{ # Create a new project -dummypackage <- tempfile("dummypackage") +dummypackage <- tempfile("dummy.package") dir.create(dummypackage) # {fusen} steps diff --git a/man/inflate_all.Rd b/man/inflate_all.Rd index 72e91700..576a3056 100644 --- a/man/inflate_all.Rd +++ b/man/inflate_all.Rd @@ -72,7 +72,7 @@ inflate_all(stylers = styler::style_pkg) # You can also inflate_all flats of another package as follows # Example with a dummy package with a flat file -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.otherpkg") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) flat_files <- add_minimal_package( diff --git a/tests/testthat/test-add_flat_template.R b/tests/testthat/test-add_flat_template.R index f372c122..3ca5ca67 100644 --- a/tests/testthat/test-add_flat_template.R +++ b/tests/testthat/test-add_flat_template.R @@ -182,7 +182,7 @@ for (template in all_templates) { main_flat_file_name <- "teaching" } - dummypackage4 <- tempfile(pattern = "all.templates.knit") + dummypackage4 <- tempfile(pattern = paste0("all.templates.knit", gsub("_", ".", template))) dir.create(dummypackage4) orig.proj <- here::here() diff --git a/tests/testthat/test-inflate-part2.R b/tests/testthat/test-inflate-part2.R index c45efce5..3076fdab 100644 --- a/tests/testthat/test-inflate-part2.R +++ b/tests/testthat/test-inflate-part2.R @@ -53,9 +53,9 @@ unlink(dummypackage, recursive = TRUE) alltemp <- tempfile("all.templates.inflate") dir.create(alltemp) -# for (pkgname in c("full", "teaching", "minimal")) { create_choices_test <- fusen:::create_fusen_choices[!grepl("dev_history", fusen:::create_fusen_choices)] for (pkgname in create_choices_test) { + # pkgname <- create_choices_test[1] # No "additional" with create_fusen # {fusen} steps path_foosen <- normalize_path_winslash(file.path(alltemp, pkgname), mustWork = FALSE) @@ -64,7 +64,7 @@ for (pkgname in create_choices_test) { usethis::with_project(path_foosen, { fill_description(pkg = path_foosen, fields = list(Title = "Dummy Package")) - usethis::use_gpl_license() + suppressMessages(usethis::use_gpl_license()) test_that("description is good", { expect_true(file.exists(file.path(path_foosen, "DESCRIPTION"))) @@ -154,7 +154,9 @@ for (pkgname in create_choices_test) { skip_if_not(interactive()) # Needs MASS, lattice, Matrix installed # quiet and checkdir - checkdir <- file.path(alltemp, paste0("checkout", pkgname)) + checkdir <- normalize_path_winslash( + file.path(alltemp, paste0("checkout", pkgname)), + mustWork = FALSE) extra_params <- glue( 'fusen::inflate(pkg = "{path_foosen}", check = TRUE, check_dir = "{checkdir}", diff --git a/tests/testthat/test-inflate_all.R b/tests/testthat/test-inflate_all.R index 2e8ea2c3..4514f986 100644 --- a/tests/testthat/test-inflate_all.R +++ b/tests/testthat/test-inflate_all.R @@ -1,7 +1,7 @@ # WARNING - Generated by {fusen} from dev/flat_inflate_all.Rmd: do not edit by hand # unlink(dummypackage, recursive = TRUE) -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.first") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) dev_file <- suppressMessages(add_minimal_package(pkg = dummypackage, overwrite = TRUE, open = FALSE)) @@ -244,7 +244,7 @@ unlink(dummypackage, recursive = TRUE) # You can also inflate_all flats of another package as follows # Example with a dummy package with a flat file -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.other.pkg") dir.create(dummypackage) suppressMessages(fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package"))) flat_files <- add_minimal_package( @@ -300,7 +300,7 @@ usethis::with_project(dummypackage, { unlink(dummypackage, recursive = TRUE) # Test inflate_all_no_check vs inflate_all with check ---- -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.nocheck") dir.create(dummypackage) suppressMessages(fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package"))) dev_file <- suppressMessages(add_minimal_package(pkg = dummypackage, overwrite = TRUE, open = FALSE)) diff --git a/vignettes/inflate-all-your-flat-files.Rmd b/vignettes/inflate-all-your-flat-files.Rmd index 98d456bc..ece2ecb5 100644 --- a/vignettes/inflate-all-your-flat-files.Rmd +++ b/vignettes/inflate-all-your-flat-files.Rmd @@ -84,7 +84,7 @@ inflate_all(stylers = styler::style_pkg) # You can also inflate_all flats of another package as follows # Example with a dummy package with a flat file -dummypackage <- tempfile("inflateall") +dummypackage <- tempfile("inflateall.otherpkg") dir.create(dummypackage) fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) flat_files <- add_minimal_package(