From 2f626cb964475c26353a59b166a2f60ea597b267 Mon Sep 17 00:00:00 2001 From: Thierry Onkelinx Date: Thu, 9 Jul 2020 19:37:05 +0200 Subject: [PATCH] More documentation checks as requested in #2 - Check for README.md - Check for NEWS.md - Check if Roxygen document is rendered - Check if README.Rmd is rendered (if it exists) --- .Rbuildignore | 1 + DESCRIPTION | 2 ++ NAMESPACE | 3 +++ NEWS.md | 18 ++++++++++++++ R/check_documentation.R | 39 +++++++++++++++++++++++++++++ README.Rmd | 55 +++++++++++++++++++++++++++++++++++++++++ README.md | 45 +++++++++++++++++++++++++++++++++ 7 files changed, 163 insertions(+) create mode 100644 NEWS.md create mode 100644 README.Rmd create mode 100644 README.md diff --git a/.Rbuildignore b/.Rbuildignore index fcbe7023..93403895 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,3 +5,4 @@ ^.dockerignore$ ^entrypoint.sh$ ^.github$ +^README\.Rmd$ diff --git a/DESCRIPTION b/DESCRIPTION index cc19accf..eabba4a8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,10 +15,12 @@ Description: An opinated set of rules for R packages and code. License: GPL-3 Imports: assertthat, + devtools, git2r, lintr, R6, rcmdcheck, + rmarkdown, usethis, yaml Suggests: diff --git a/NAMESPACE b/NAMESPACE index b02c05d0..dcce37c1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ importFrom(assertthat,has_name) importFrom(assertthat,is.flag) importFrom(assertthat,is.string) importFrom(assertthat,noNA) +importFrom(devtools,document) importFrom(git2r,branch_target) importFrom(git2r,branches) importFrom(git2r,commits) @@ -26,6 +27,8 @@ importFrom(git2r,sha) importFrom(git2r,status) importFrom(lintr,lint_package) importFrom(rcmdcheck,rcmdcheck) +importFrom(rmarkdown,github_document) +importFrom(rmarkdown,render) importFrom(stats,na.omit) importFrom(usethis,use_tidy_description) importFrom(utils,file_test) diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 00000000..494b36ca --- /dev/null +++ b/NEWS.md @@ -0,0 +1,18 @@ +# checklist 0.1.1 + +* Added a `NEWS.md` file to track changes to the package. +* Rework `checklist_template()` into `write_checklist()`. +* Add `check_description()`. +* Add `check_documentation()`. +* Activate GitHub action `inbo/check_package`. + +# checklist 0.1.0 + +* Initital version. +* Create `checklist` R6 class. +* Add `check_cran()`. +* Add `check_lintr()`. +* Add `check_package()`. +* Add `read_checklist()`. +* Add `checklist_template()`. +* Add Dockerimage for GitHub actions. diff --git a/R/check_documentation.R b/R/check_documentation.R index 8682f39d..acdb9649 100644 --- a/R/check_documentation.R +++ b/R/check_documentation.R @@ -1,10 +1,13 @@ #' Check the documentation #' @inheritParams read_checklist #' @export +#' @importFrom devtools document +#' @importFrom rmarkdown github_document render check_documentation <- function(x = ".") { if (!inherits(x, "Checklist") || !"checklist" %in% x$get_checked) { x <- read_checklist(x = x) } + rd_files <- c( file.path(x$get_path, "NAMESPACE"), list.files( @@ -16,6 +19,42 @@ check_documentation <- function(x = ".") { doc_error <- sprintf( "Documentation in %s not generated by `roxygen2`", rd_files[!ok] ) + + repo <- repository(x$get_path) + clean <- is_workdir_clean(repo) + document(x$get_path) + if (clean && !is_workdir_clean(repo)) { + doc_error <- c( + doc_error, + "Missing documentation. Run `devtools::document()`" + ) + reset(repo) + } + + if (file_test("-f", file.path(x$get_path, "README.Rmd"))) { + render( + file.path(x$get_path, "README.Rmd"), + output_format = github_document(html_preview = FALSE), + encoding = "UTF-8" + ) + if (clean && !is_workdir_clean(repo)) { + doc_error <- c( + doc_error, + "Missing documentation. Run `devtools::document()`" + ) + reset(repo) + } + } + + doc_error <- c( + doc_error, + "Don't use NEWS.Rmd"[file_test("-f", file.path(x$get_path, "NEWS.Rmd"))] + ) + + md_files <- file.path(x$get_path, c("NEWS.md", "README.md")) + ok <- file_test("-f", md_files) + doc_error <- c(doc_error, sprintf("Missing %s", basename(md_files[!ok]))) + x$add_error(doc_error, "documentation") return(x) } diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 00000000..de68276f --- /dev/null +++ b/README.Rmd @@ -0,0 +1,55 @@ +--- +output: github_document +--- + + + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +# checklist + + + + +The goal of `checklist` is to provide an elaborate and strict set of checks for R packages and R code. + +## Installation + +You can install the development version from [GitHub](https://github.com/) with: + +``` r +# install.packages("remotes") +remotes::install_github("inbo/checklist") +``` + +## Examples + +You can run the full list of checks + +```{r example-full, eval = FALSE} +library(checklist) +check_package() +``` + +Or run the individual checks + +```{r example-detail, eval = FALSE} +check_cran() +check_lintr() +check_description() +check_documentation() +``` + + +Create a `checklist.yml` to allow some of warnings or notes. + +```{r example-checklist, eval = FALSE} +write_checklist() +``` diff --git a/README.md b/README.md new file mode 100644 index 00000000..e8416662 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ + + + +# checklist + + + + + +The goal of `checklist` is to provide an elaborate and strict set of +checks for R packages and R code. + +## Installation + +You can install the development version from +[GitHub](https://github.com/) with: + +``` r +# install.packages("remotes") +remotes::install_github("inbo/checklist") +``` + +## Examples + +You can run the full list of checks + +``` r +library(checklist) +check_package() +``` + +Or run the individual checks + +``` r +check_cran() +check_lintr() +check_description() +check_documentation() +``` + +Create a `checklist.yml` to allow some of warnings or notes. + +``` r +write_checklist() +```