Skip to content

Commit f1cc91c

Browse files
pwildenhainlorenzwalthert
authored andcommitted
♻️ Add Rmds to parsable-R hook
1 parent d2091d7 commit f1cc91c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.pre-commit-hooks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
description: check if a .R file is parsable
3434
entry: Rscript inst/hooks/exported/parsable-R.R
3535
language: r
36-
files: '\.[rR]$'
36+
files: '\.[rR](md)?$'
3737
minimum_pre_commit_version: "2.13.0"
3838
- id: readme-rmd-rendered
3939
name: readme-rmd-rendered

inst/hooks/exported/parsable-R.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
files <- commandArgs(trailing = TRUE)
33

44
out <- lapply(files, function(path) {
5+
is_rmd <- grepl("\\.[rR]md$", path)
6+
if (is_rmd) {
7+
dir <- tempdir()
8+
path <- knitr::purl(
9+
input = path,
10+
output = paste0(dir, "/file.R"),
11+
quiet = TRUE,
12+
documentation = FALSE
13+
)
14+
}
15+
516
tryCatch(
617
parse(path),
718
error = function(x) stop("File ", path, " is not parsable", call. = FALSE)

0 commit comments

Comments
 (0)