Skip to content

Commit 6b56ba4

Browse files
committed
Allow styling of Rnw files from style_dir() and style_pkg() and add a few more tests
1 parent 4ede116 commit 6b56ba4

File tree

19 files changed

+265
-10
lines changed

19 files changed

+265
-10
lines changed

R/set-assert-args.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ set_and_assert_arg_filetype <- function(filetype) {
3838
#' @param lowercase_filetype A vector with file types to check, all lower case.
3939
#' @keywords internal
4040
assert_filetype <- function(lowercase_filetype) {
41-
if (!all(lowercase_filetype %in% c("r", "rmd"))) {
41+
if (!all(lowercase_filetype %in% c("r", "rmd", "rnw"))) {
4242
stop(
4343
"filetype must not contain other values than 'R'",
44-
"or 'Rmd' (case is ignored).",
44+
"'Rmd' or 'Rnw' (case is ignored).",
4545
call. = FALSE
4646
)
4747
}

R/ui.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ NULL
1919
#' conveniently constructed via the `style` argument and `...`. See
2020
#' 'Examples'.
2121
#' @param filetype Vector of file extensions indicating which file types should
22-
#' be styled. Case is ignored, and the `.` is optional, e.g. `c(".R", ".Rmd")`
23-
#' or `c("r", "rmd")`.
22+
#' be styled. Case is ignored, and the `.` is optional, e.g. `c(".R", ".Rmd",
23+
#' ".Rnw")` or `c("r", "rmd", "rnw")`.
2424
#' @param exclude_files Character vector with paths to files that should be
2525
#' excluded from styling.
2626
#' @param include_roxygen_examples Whether or not to style code in roxygen
@@ -102,6 +102,16 @@ prettify_pkg <- function(transformers,
102102
readme <- dir(pattern = "^readme\\.rmd$", ignore.case = TRUE)
103103
}
104104

105+
if ("\\.rnw" %in% filetype) {
106+
vignette_files <- append(
107+
vignette_files,
108+
dir(
109+
path = "vignettes", pattern = "\\.rnw$",
110+
ignore.case = TRUE, recursive = TRUE, full.names = TRUE
111+
)
112+
)
113+
}
114+
105115
files <- setdiff(c(r_files, vignette_files, readme), exclude_files)
106116
transform_files(files, transformers, include_roxygen_examples)
107117
}

man/prettify_any.Rd

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

man/style_dir.Rd

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

man/style_pkg.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Package: xyzpackage
2+
Title: What the Package Does (one line, title case)
3+
Version: 0.0.0.9000
4+
Authors@R: person("First", "Last", email = "[email protected]", role = c("aut", "cre"))
5+
Description: What the package does (one paragraph).
6+
Depends: R (>= 3.3.2)
7+
License: What license is it under?
8+
Encoding: UTF-8
9+
LazyData: true
10+
Suggests: testthat
11+
LinkingTo:
12+
Rcpp
13+
Imports:
14+
Rcpp
15+
RoxygenNote: 6.0.1.9000
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated by roxygen2: do not edit by hand
2+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
timesTwo <- function(x) {
5+
.Call("_xyzpackage_timesTwo", PACKAGE = "xyzpackage", x)
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hello_world <- function() {
2+
print("hello, world")
3+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
output: github_document
3+
---
4+
5+
<!-- README.md is generated from README.Rmd. Please edit that file -->
6+
7+
```{r setup, include = FALSE}
8+
knitr::opts_chunk$set(
9+
collapse = TRUE,
10+
comment = "#>",
11+
fig.path = "man/figures/README-"
12+
)
13+
```
14+
# styler
15+
16+
The goal of styler is to ...
17+
18+
## Installation
19+
20+
You can install styler from github with:
21+
22+
```{r gh-installation, eval = FALSE}
23+
# install.packages("devtools")
24+
devtools::install_github("jonmcalder/styler")
25+
```
26+
27+
## Example
28+
29+
This is a basic example which shows you how to solve a common problem:
30+
31+
```{r example}
32+
## basic example code
33+
```

0 commit comments

Comments
 (0)