Skip to content

Commit e7777f2

Browse files
Merge pull request #824 from JohannesNE/patch-1
- Treat .Rmarkdown files as .Rmd files (#824).
2 parents d31ee93 + 2e64b07 commit e7777f2

File tree

14 files changed

+193
-18
lines changed

14 files changed

+193
-18
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Don't break line before comments in pipes (#822).
44

5+
* Files with `.Rmarkdown` extension are now recognised as an R markdown files in `style_file()` and friends (#824)
6+
57
# styler 1.5.1
68

79
## Alignment detection

R/set-assert-args.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ set_and_assert_arg_filetype <- function(filetype) {
7171
#' @importFrom rlang abort
7272
#' @keywords internal
7373
assert_filetype <- function(lowercase_filetype) {
74-
if (!all(lowercase_filetype %in% c("r", "rmd", "rnw", "rprofile"))) {
74+
if (!all(lowercase_filetype %in% c("r", "rmd", "rmarkdown", "rnw", "rprofile"))) {
7575
abort(paste(
7676
"filetype must not contain other values than 'R', 'Rprofile',",
77-
"'Rmd' or 'Rnw' (case is ignored)."
77+
"'Rmd', 'Rmarkdown' or 'Rnw' (case is ignored)."
7878
))
7979
}
8080
}

R/ui-styling.R

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NULL
66
#' Prettify R source code
77
#'
88
#' Performs various substitutions in all `.R` files in a package
9-
#' (code and tests). One can also (optionally) style `.Rmd` and/or
9+
#' (code and tests). One can also (optionally) style `.Rmd`, `.Rmarkdown` and/or
1010
#' `.Rnw` files (vignettes and readme) by changing the `filetype` argument.
1111
#' Carefully examine the results after running this function!
1212
#'
@@ -95,7 +95,7 @@ style_pkg <- function(pkg = ".",
9595
#' @param filetype Vector of file extensions indicating which file types should
9696
#' be styled. Case is ignored, and the `.` is optional, e.g.
9797
#' `c(".R", ".Rmd")`, or `c("r", "rmd")`. Supported values (after
98-
#' standardization) are: "r", "rprofile", "rmd", "rnw".
98+
#' standardization) are: "r", "rprofile", "rmd", "rmarkdown", "rnw". Rmarkdown is treated as Rmd.
9999
#' @param exclude_files Character vector with paths to files that should be
100100
#' excluded from styling.
101101
#' @param exclude_dirs Character vector with directories to exclude
@@ -138,6 +138,21 @@ prettify_pkg <- function(transformers,
138138
)
139139
}
140140

141+
if ("\\.rmarkdown" %in% filetype_) {
142+
vignette_files <- append(
143+
vignette_files,
144+
dir_without_.(
145+
path = "vignettes", pattern = "\\.rmarkdown$"
146+
)
147+
)
148+
readme <- append(
149+
readme,
150+
dir_without_.(
151+
path = ".", pattern = "^readme\\.rmarkdown$"
152+
)
153+
)
154+
}
155+
141156
if ("\\.rnw" %in% filetype_) {
142157
vignette_files <- append(
143158
vignette_files,
@@ -199,7 +214,7 @@ style_text <- function(text,
199214

200215
#' Prettify arbitrary R code
201216
#'
202-
#' Performs various substitutions in all `.R`, `.Rmd` and/or `.Rnw` files
217+
#' Performs various substitutions in all `.R`, `.Rmd`, `.Rmarkdown` and/or `.Rnw` files
203218
#' in a directory (by default only `.R` files are styled - see `filetype` argument).
204219
#' Carefully examine the results after running this function!
205220
#' @param path Path to a directory with files to transform.
@@ -283,7 +298,7 @@ prettify_any <- function(transformers,
283298
)
284299
}
285300

286-
#' Style `.R`, `.Rmd` or `.Rnw` files
301+
#' Style `.R`, `.Rmd`, `.Rmarkdown` or `.Rnw` files
287302
#'
288303
#' Performs various substitutions in the files specified.
289304
#' Carefully examine the results after running this function!

R/utils-files.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ is_rprofile_file <- function(path) {
66
grepl(".rprofile", path, ignore.case = TRUE)
77
}
88
is_rmd_file <- function(path) {
9-
grepl("\\.Rmd$", path, ignore.case = TRUE)
9+
grepl("\\.(Rmd|Rmarkdown)$", path, ignore.case = TRUE)
1010
}
1111

1212
is_rnw_file <- function(path) {

man/prettify_any.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/prettify_pkg.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/style_dir.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/style_file.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/style_pkg.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: "random-rmd-script"
3+
author: "Lorenz Walthert"
4+
date: "11/25/2017"
5+
output: html_document
6+
---
7+
8+
```{r setup, include=FALSE}
9+
1 + 1
10+
```
11+
12+
## R Markdown
13+
14+
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
15+
16+
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
17+
18+
```{r cars}
19+
summary(cars)
20+
```
21+
22+
## Including Plots
23+
24+
You can also embed plots, for example:
25+
26+
```{r pressure, echo=FALSE}
27+
plot(pressure)
28+
```
29+
30+
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

0 commit comments

Comments
 (0)