Skip to content

Commit

Permalink
Merge pull request #227 from ThinkR-open/v0.5.2-before-cran
Browse files Browse the repository at this point in the history
V0.5.2 before cran
  • Loading branch information
statnmap authored Aug 17, 2023
2 parents 7271887 + a84d693 commit 0de486b
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 70 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-1565-9313")),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/add_flat_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/create_fusen_rsproject.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/fill_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' @examples
#' # Create a new project
#' dummypackage <- tempfile("dummypackage")
#' dummypackage <- tempfile("dummy.package.desc")
#' dir.create(dummypackage)
#'
#' fill_description(
Expand Down
18 changes: 14 additions & 4 deletions R/inflate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion R/inflate_all.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 10 additions & 7 deletions R/register_config_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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))
Expand Down
32 changes: 5 additions & 27 deletions dev/dev_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"))
Expand All @@ -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()
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions dev/flat_create_flat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions dev/flat_inflate_all.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))
Expand Down
17 changes: 10 additions & 7 deletions dev/flat_register_config_file.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion man/add_flat_template.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fill_description.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/inflate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/inflate_all.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-add_flat_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-inflate-part2.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")))
Expand Down Expand Up @@ -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}",
Expand Down
Loading

0 comments on commit 0de486b

Please sign in to comment.