Skip to content

Commit

Permalink
More documentation checks as requested in #2
Browse files Browse the repository at this point in the history
- Check for README.md
- Check for NEWS.md
- Check if Roxygen document is rendered
- Check if README.Rmd is rendered (if it exists)
  • Loading branch information
ThierryO committed Jul 9, 2020
1 parent b146c0d commit 2f626cb
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
^.dockerignore$
^entrypoint.sh$
^.github$
^README\.Rmd$
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 39 additions & 0 deletions R/check_documentation.R
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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)
}
55 changes: 55 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# checklist

<!-- badges: start -->
<!-- badges: end -->

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()
```
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# checklist

<!-- badges: start -->

<!-- badges: end -->

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()
```

0 comments on commit 2f626cb

Please sign in to comment.