Skip to content

Commit

Permalink
Merge pull request #223 from ThinkR-open/before-cran
Browse files Browse the repository at this point in the history
doc: improve error messages
  • Loading branch information
statnmap committed Jun 30, 2023
2 parents 5bb8ffd + a6fa99c commit d617172
Show file tree
Hide file tree
Showing 29 changed files with 357 additions and 89 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: fusen
Title: Build a Package from Rmarkdown Files
Version: 0.5.0.9008
Version: 0.5.1
Authors@R: c(
person("Sebastien", "Rochette", , "sebastien@thinkr.fr", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-1565-9313")),
Expand Down Expand Up @@ -47,7 +47,7 @@ Suggests:
withr
VignetteBuilder:
knitr
Config/fusen/version: 0.5.0.9007
Config/fusen/version: 0.5.0.9011
Config/Needs/website: ThinkR-open/thinkrtemplate
Config/testthat/edition: 3
Encoding: UTF-8
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
@@ -1,4 +1,4 @@
# fusen (development)
# fusen 0.5.1

## New features

Expand All @@ -17,6 +17,7 @@
- Arguments `rmd` and `name` in function `inflate()` now lead to errors (Deprecated since v0.3.0).
- `add_dev_history()` was deprecated since v0.3.0 in favor of `add_flat_template()`. Now `add_dev_history()` only adds a "dev_history.Rmd" file in the "dev/" directory.
- `add_flat_template(template = "minimal")` no longer exists to avoid confusion between minimal package or minimal flat file. Indeed, now there are `add_flat_template(template = "minimal_package")` (also `add_minimal_package()`) or `add_flat_template(template = "minimal_flat")` (also `add_minimal_flat()`). The latter doing exactly the same as `add_additional()` (#187)
- `create_fusen()` still uses `minimal` as `minimal_package`

## Bug fixes

Expand All @@ -25,6 +26,7 @@

## Major changes

- `create_fusen()` and the RStudio gui interface now accept `flat_file` parameter to name the first flat file as well as the first function (when using 'minimal' template).
- The tips and tricks vignette shortly presents how to combine {fusen} and {golem} (#187)
- Incorrect function names issued from addins or `add_flat_template()` are cleaned before being included in the flat file to follow underscore rule.

Expand Down
2 changes: 1 addition & 1 deletion R/add_flat_template.R
Expand Up @@ -100,7 +100,7 @@ add_dev_history <- function(pkg = ".",
#'
#' - "full": The full template with a reproducible package that can directly be inflated.
#' It comes along with the "dev_history" template. Default.
#' - "minimal_package": Minimal template to start a new package when you already know {fusen}, along with the "dev_history" template.
#' - "minimal_package": Minimal template to start a new package when you already know {fusen}, along with the "dev_history" template. Note that this is called "minimal" in `create_fusen()`.
#' - "minimal_flat" or "additional": Template for a new minimal flat file only.
#' - "teaching": Template with a reproducible package, simpler than "full", but everything to
#' teach the minimal structure of a package.
Expand Down
13 changes: 9 additions & 4 deletions R/create_fusen_rsproject.R
@@ -1,15 +1,17 @@
#' Create a new fusen project
#'
#' @param path Character. Path where to create the new fusen project.
#' @param template Character. Name of the template to be used among "full", "minimal" and "teaching".
#' @param template Character. Name of the template to be used among "full", "minimal", "teaching" and "dev_history".
#' @param flat_name Character. Filename of the flat file created.
#' This is also used to name the first function of the file in `minimal` template.
#' @param open Logical. Should the newly created project be opened ?
#' @param overwrite Logical. Allow to overwrite 'dev/' files if path exists.
#' @param with_git Logical. Should git be initialized in the newly created project ?
#'
#' @details
#' See \code{\link{add_flat_template}} for details about the different options for `template`.
#' Template "additional" is not available here as it is meant to be used with an already
#' existing fusen.
#' existing 'fusen'.
#'
#' @importFrom cli cli_alert_warning cli_alert_danger cat_rule cli_alert_success
#' @export
Expand All @@ -19,7 +21,8 @@
#' my_path <- tempfile("mypkg")
#' create_fusen(path = my_path, template = "full", open = FALSE)
create_fusen <- function(path,
template = c("full", "minimal", "teaching"),
template = c("full", "minimal", "teaching", "dev_history"),
flat_name = template,
open = TRUE,
overwrite = FALSE,
with_git = FALSE) {
Expand Down Expand Up @@ -88,10 +91,10 @@ create_fusen <- function(path,
if (template == "minimal") {
template <- "minimal_package"
}
cli::cat_rule(glue::glue("Adding dev/flat_{template}.Rmd"))
dev_file <- add_flat_template(
template = template,
pkg = path,
flat_name = flat_name,
overwrite = TRUE,
open = FALSE,
dev_dir = "dev"
Expand Down Expand Up @@ -119,10 +122,12 @@ create_fusen <- function(path,
#' @noRd
create_fusen_gui <- function(path,
template,
flat_name = template,
with_git) {
create_fusen(
path = file.path(getwd(), path),
template = template,
flat_name = flat_name,
open = FALSE, # Project opening is done spontaneously by Rstudio Project Wizard
with_git = with_git
)
Expand Down
11 changes: 6 additions & 5 deletions R/inflate_all.R
Expand Up @@ -100,12 +100,13 @@ inflate_all <- function(pkg = ".", document = TRUE, check = TRUE, open_vignette

if (stop_after_infos) {
cli::cli_abort(
paste0(
" `inflate_all()` requires a configuration file to work properly.",
" There is no configuration file at this place in your package: '", config_file, "'.",
"\nYour active flat files must be individually inflated at least once manually before you can use `inflate_all()`.",
c(
" {.fn fusen::inflate_all} requires a configuration file to work properly.",
" There is no configuration file at this place in your package: '{config_file}'",
"\nYour active flat files must be individually inflated at least once manually before you can use {.fn inflate_all}.",
" This will create a proper configuration file with a section for each flat file.",
"\nThis error is common if you were using 'fusen' prior to v0.5.1. Read `vignette('inflate-all-your-flat-files', package = 'fusen')` for more information."
"\nThis error is common if you were using {.pkg fusen} prior to v0.5.1.",
"Read `vignette('{.vignette [inflate-all-your-flat-files](fusen::inflate-all-your-flat-files)}', package = 'fusen')` for more information."
)
)
return(NULL)
Expand Down
25 changes: 23 additions & 2 deletions R/init_share_on_github.R
@@ -1,18 +1,38 @@
# WARNING - Generated by {fusen} from dev/flat_init_share_on_github.Rmd: do not edit by hand

#' Initiate GitHub to share your work on a website
#' Initiate GitHub to share your package on a website
#'
#' This uses {pkgdown} to share the documentation of the package through GitHub Actions.
#' You may need to run `usethis::create_github_token()`, then `gitcreds::gitcreds_set()` before.
#'
#' @param ask Logical. `TRUE` (default) to ask the user to apply the instructions each time needed,
#' or `FALSE` if the user already know what to do.
#'
#' @details
#'
#' `init_share_on_github()` runs multiple steps to be able to share a proper package on GitHub:
#'
#' - Start versionning with git if not already
#' - Connect to your GitHub account
#' - Create a minimal DESCRIPTION file if missing
#' + You will have to update its content with your information after deployment
#' - Add NEWS file to present modifications of your releases
#' - Add README.Rmd and knit it to README.md to quickly present the aim and the use of your package
#' - Init continuous integration (CI)
#' + Check the package on Linux, Windows and MacOS
#' + Calculate code coverage. Note that you may need to connect to <https://about.codecov.io/> to see the results of the code coverage.
#' - Init continuous deployment (CD) of the {pkgdown} website documentation
#' - Commit and push to GitHub
#' - List remaining manual steps to make the website public
#'
#' Read `vignette("share-on-a-github-website", package = "fusen")`
#'
#' @return The URL of the website created
#' @export
#'
#' @examples
#' \dontrun{
#' # This modifies the current directory and send it on GitHub
#' init_share_on_github()
#' }
init_share_on_github <- function(ask = TRUE) {
Expand Down Expand Up @@ -73,7 +93,7 @@ init_share_on_github <- function(ask = TRUE) {
cli::cli_text(
cli::cli_alert_info(
"You decided to stop the procedure. \nYour package was not send to {.url https://github.com}",
"\nYou can run again `fusen::init_share_on_github()` to finish the procedure if you want."
"\nYou can run again {.fn fusen::init_share_on_github} to finish the procedure if you want."
)
)
return(NULL)
Expand Down Expand Up @@ -113,6 +133,7 @@ init_share_on_github <- function(ask = TRUE) {
usethis::use_github_action("check-standard")
usethis::use_github_action("pkgdown")
usethis::use_github_action("test-coverage")
usethis::use_coverage(type = "codecov")

# Get info for website
github_url <- gert::git_remote_info()$url
Expand Down
22 changes: 12 additions & 10 deletions R/register_config_file.R
Expand Up @@ -44,7 +44,7 @@
#' # Add a not registered file to the package
#' cat("# test R file\n", file = file.path(dummypackage, "R", "to_keep.R"))
#'
#' # Use the fonction to check the list of files
#' # Use the function to check the list of files
#' out_csv <- check_not_registered_files(dummypackage)
#' out_csv
#' # Read the csv to see what is going on
Expand Down Expand Up @@ -131,15 +131,17 @@ check_not_registered_files <- function(path = ".", guess = TRUE, to_csv = TRUE,
# Save for manual modification
if (isTRUE(to_csv)) {
write.csv(res_new, csv_file, row.names = FALSE)
cli::cli_alert_info(paste(
"\nSome files in your package are not registered in the configuration file:", config_file,
"\n'fusen' uses a configuration file to store the structure of your package and help you clean it when needed.",
"\nYou will find a list of unregistered files there:", csv_file,
"that you can open with", paste0("`file.edit('", csv_file, "')`"),
"\nDelete unregistered files that you do not need anymore. Then run `fusen::register_all_to_config()`.",
"\nAfter that, this message should not appear in your next `inflate_all()` calls.",
"\n For more information, read `vignette('register-files-in-config', package = 'fusen')`"
))
cli::cli_text(
cli::cli_alert_info(c(
"\nSome files in your package are not registered in the configuration file: {config_file}",
"\n{.pkg fusen} uses a configuration file to store the structure of your package and help you clean it when needed.",
"\nYou will find a list of unregistered files there: {.path csv_file}",
" that you can open with {.run file.edit('{csv_file}')}",
"\nDelete unregistered files that you do not need anymore. Then run {.fn fusen::register_all_to_config}.",
"\nAfter that, this message should not appear in your next {.fn fusen::inflate_all} calls.",
"\nFor more information, read `vignette('{.vignette [register-files-in-config](fusen::register-files-in-config)}', package = 'fusen')`"
))
)

if (isTRUE(open) & interactive()) {
if (requireNamespace("rstudioapi") &&
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Expand Up @@ -19,7 +19,7 @@ knitr::opts_chunk$set(
[![fusen status badge](https://thinkr-open.r-universe.dev/badges/fusen)](https://thinkr-open.r-universe.dev)
[![CRAN status](https://www.r-pkg.org/badges/version/fusen)](https://CRAN.R-project.org/package=fusen)
[![R-CMD-check](https://github.com/ThinkR-open/fusen/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ThinkR-open/fusen/actions/workflows/R-CMD-check.yaml)
[![codecov](https://app.codecov.io/gh/ThinkR-open/fusen/branch/main/graph/badge.svg?token=V0HOSAY8WW)](https://app.codecov.io/gh/ThinkR-open/fusen)
[![codecov](https://codecov.io/gh/ThinkR-open/fusen/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ThinkR-open/fusen)
[![](https://cranlogs.r-pkg.org/badges/fusen)](https://cran.r-project.org/package=fusen)
<!-- badges: end -->

Expand All @@ -28,7 +28,7 @@ knitr::opts_chunk$set(
> If you know how to create a Rmarkdown file, then you know how to build a package.

```{r echo=FALSE, out.width="65%", fig.align='center'}
```{r echo=FALSE, out.width="75%", fig.align='center'}
knitr::include_graphics("man/figures/fusen_inflate_functions.png")
```

Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -10,7 +10,7 @@ badge](https://thinkr-open.r-universe.dev/badges/fusen)](https://thinkr-open.r-u
[![CRAN
status](https://www.r-pkg.org/badges/version/fusen)](https://CRAN.R-project.org/package=fusen)
[![R-CMD-check](https://github.com/ThinkR-open/fusen/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ThinkR-open/fusen/actions/workflows/R-CMD-check.yaml)
[![codecov](https://app.codecov.io/gh/ThinkR-open/fusen/branch/main/graph/badge.svg?token=V0HOSAY8WW)](https://app.codecov.io/gh/ThinkR-open/fusen)
[![codecov](https://codecov.io/gh/ThinkR-open/fusen/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ThinkR-open/fusen)
[![](https://cranlogs.r-pkg.org/badges/fusen)](https://cran.r-project.org/package=fusen)
<!-- badges: end -->

Expand All @@ -19,7 +19,7 @@ status](https://www.r-pkg.org/badges/version/fusen)](https://CRAN.R-project.org/
> If you know how to create a Rmarkdown file, then you know how to build
> a package.
<img src="man/figures/fusen_inflate_functions.png" width="65%" style="display: block; margin: auto;" />
<img src="man/figures/fusen_inflate_functions.png" width="75%" style="display: block; margin: auto;" />

*Fill the flat Rmd (or qmd) template with everything in one place and
{fusen} will inflate the identified parts in the correct package files
Expand Down
25 changes: 25 additions & 0 deletions dev/cran-comments-history.md
@@ -1,3 +1,28 @@
# v0.5.1
## R CMD check results

0 errors | 0 warnings | 0 note

* Tested on rhub, winbuilder and macbuilder

### Comments

- Found the following (possibly) invalid URLs:
URL: https://codecov.io/gh/ThinkR-open/fusen (moved to
https://app.codecov.io/gh/ThinkR-open/fusen)
From: README.md
Status: 301
Message: Moved Permanently

Please change http --> https, add trailing slashes, or follow moved
content as appropriate.

Please fix and resubmit.

=> Thank you. Sorry for the redirections, I do not always find the correct combination for codecov...
I followed the URL to use a not redirected content: `[![codecov](https://codecov.io/gh/ThinkR-open/fusen/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ThinkR-open/fusen)`
I did not find 'http' calls though

# v0.4.2
## R CMD check results

Expand Down
10 changes: 8 additions & 2 deletions dev/dev_history.R
Expand Up @@ -172,11 +172,15 @@ unlink(skeleton_dir, recursive = TRUE)

# _Check in interactive test-inflate for templates and Addins ----
pkgload::load_all()

Sys.setenv("NOT_CRAN" = "true")
testthat::test_dir("tests/testthat/")
testthat::test_file("tests/testthat/test-inflate-part1.R")
testthat::test_file("tests/testthat/test-inflate-part2.R")
testthat::test_file("tests/testthat/test-inflate_all.R")
testthat::test_file("tests/testthat/test-add_flat_template.R")
testthat::test_file("tests/testthat/test-skeleton.R")
Sys.setenv("NOT_CRAN" = "false")

Sys.setenv("FUSEN_TEST_PUBLISH" = "TRUE")
testthat::test_file("tests/testthat/test-init_share_on_github.R")
Expand Down Expand Up @@ -222,8 +226,10 @@ devtools::check(args = c("--no-manual", "--as-cran"))

# Check content
# remotes::install_github("ThinkR-open/checkhelper")
checkhelper::find_missing_tags()
checkhelper::check_clean_userspace(pkg = ".")
tags <- checkhelper::find_missing_tags()
View(tags$functions)
out <- checkhelper::check_clean_userspace(pkg = ".")
out
checkhelper::check_as_cran()

# Check spelling
Expand Down
15 changes: 11 additions & 4 deletions dev/flat_create_flat.Rmd
Expand Up @@ -31,7 +31,7 @@ library(tools)
#'
#' - "full": The full template with a reproducible package that can directly be inflated.
#' It comes along with the "dev_history" template. Default.
#' - "minimal_package": Minimal template to start a new package when you already know {fusen}, along with the "dev_history" template.
#' - "minimal_package": Minimal template to start a new package when you already know {fusen}, along with the "dev_history" template. Note that this is called "minimal" in `create_fusen()`.
#' - "minimal_flat" or "additional": Template for a new minimal flat file only.
#' - "teaching": Template with a reproducible package, simpler than "full", but everything to
#' teach the minimal structure of a package.
Expand Down Expand Up @@ -441,14 +441,18 @@ unlink(dummypackage3, recursive = TRUE)
all_templates <- c("full", "minimal_package", "additional", "teaching") # "dev_history"
for (template in all_templates) {
# template <- all_templates[1]
main_flat_file_name <- template
if (template == "minimal_package") {
main_flat_file_name <- "minimal"
}
dummypackage4 <- tempfile(pattern = "all.templates.knit")
dir.create(dummypackage4)
# Add
orig.proj <- here::here()
# Add
dev_file_path <- suppressMessages(add_flat_template(pkg = dummypackage4, template = template, open = FALSE))
flat_file <- dev_file_path[grepl("flat", dev_file_path)]
Expand All @@ -461,17 +465,20 @@ for (template in all_templates) {
)
cat(enc2utf8(lines_template), file = flat_file, sep = "\n")
withr::with_dir(dummypackage4, {
withr::with_dir(dummypackage4, {
usethis::proj_set(dummypackage4)
here:::do_refresh_here(dummypackage4)
if (rmarkdown::pandoc_available("1.12.3")) {
rmarkdown::render(
input = file.path(dummypackage4, "dev", paste0("flat_", main_flat_file_name, ".Rmd")),
output_file = file.path(dummypackage4, "dev", paste0("flat_", main_flat_file_name, ".html")),
envir = new.env(), quiet = TRUE
)
}
usethis::proj_set(NULL)
here:::do_refresh_here(orig.proj)
})
test_that(paste0("template", template, "runs as markdown"), {
Expand Down
18 changes: 12 additions & 6 deletions dev/flat_inflate_all.Rmd
Expand Up @@ -102,12 +102,13 @@ inflate_all <- function(pkg = ".", document = TRUE, check = TRUE, open_vignette
if (stop_after_infos) {
cli::cli_abort(
paste0(
" `inflate_all()` requires a configuration file to work properly.",
" There is no configuration file at this place in your package: '", config_file, "'.",
"\nYour active flat files must be individually inflated at least once manually before you can use `inflate_all()`.",
c(
" {.fn fusen::inflate_all} requires a configuration file to work properly.",
" There is no configuration file at this place in your package: '{config_file}'",
"\nYour active flat files must be individually inflated at least once manually before you can use {.fn inflate_all}.",
" This will create a proper configuration file with a section for each flat file.",
"\nThis error is common if you were using 'fusen' prior to v0.5.1. Read `vignette('inflate-all-your-flat-files', package = 'fusen')` for more information."
"\nThis error is common if you were using {.pkg fusen} prior to v0.5.1.",
"Read `vignette('{.vignette [inflate-all-your-flat-files](fusen::inflate-all-your-flat-files)}', package = 'fusen')` for more information."
)
)
return(NULL)
Expand Down Expand Up @@ -239,7 +240,12 @@ usethis::with_project(dummypackage, {
test_that("error if no config file exists", {
# if no config file exists, we raise an error
expect_error(inflate_all(), regexp = "requires a configuration file to work properly")
withr::with_options(list(cli.width = 80), {
# cli.width is requires as cli output is wrapped to the console size
expect_error(inflate_all(),
regexp = "requires a configuration file to[[:space:]]work properly"
)
})
})
# we inflate the flat file
Expand Down

0 comments on commit d617172

Please sign in to comment.