Skip to content

Don't check readme.Rmd #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* `style-files` hook fails more informatively if required package is not listed
in `additional_dependencies:` (#333).
* `deps-in-desc` always excludes `README.md` (#336).
* Document timeout and other problems with pre-commit.ci (#335).

# precommit v0.2.0
Expand Down
4 changes: 4 additions & 0 deletions inst/hooks/exported/deps-in-desc.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pre_installed <- c(

arguments <- docopt::docopt(doc)
deps_in_desc <- function(file, arguments) {
if (basename(file) == "README.Rmd") {
# is .Rbuildignored, dependencies irrelevant
return()
}
if (grepl("(\\.Rmd|\\.Rnw|\\.rmd|\\.rnw)$", file)) {
file <- knitr::purl(file, output = tempfile())
}
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/in/README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ output: github_document
---

# This is a readme

```{r}
knitr::opts_chunk$set(
fig.path = "man/figures/",
eval = FALSE
)
```
8 changes: 8 additions & 0 deletions tests/testthat/test-hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ run_test("deps-in-desc",
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
)

# README.Rmd is excluded
run_test("deps-in-desc",
"README.Rmd",
suffix = "", error_msg = NULL,
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf"))
)



# Rnw
run_test("deps-in-desc",
Expand Down
6 changes: 2 additions & 4 deletions vignettes/available-hooks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ specified in `DESCRIPTION`.
## `deps-in-desc`

Checks if packages used with the `pkgname::fun()` syntax are listed in your
DESCRIPTION file. Flag `allow_private_imports` lets the user specify that
DESCRIPTION file. Note that `README.Rmd` is never checked. Flag
`allow_private_imports` lets the user specify that
private imports into the package namespace are tolerable, e.g. `somepkg:::x()`.
Flag not set by default, i.e. the hook will fail if such a call is found.

Expand All @@ -217,9 +218,6 @@ Flag not set by default, i.e. the hook will fail if such a call is found.
args: [--allow_private_imports]
```

Note that for Rmd or Rnw documents, we use `knitr::purl()` to get the R code and
code chunk headers cannot contain code that has dependencies outside the header,
see also [yihui/knitr#1938](https://github.com/yihui/knitr/issues/1938).

This hook does not modify the file `DESCRIPTION` because the user should decide
for each package if it should go to `Imports:` or `Suggests:`, which can be done
Expand Down