Skip to content

Commit 584a294

Browse files
committed
Add error msg & improve documentation of internal functions
1 parent e1e942c commit 584a294

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

R/style_rmd.R

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#' Transform code from R or Rmd files
22
#'
3+
#' A wrapper for [utf8::transform_lines_enc()] which initiates the styling of
4+
#' either R or Rmd files by passing the relevant transformer function for each
5+
#' case.
6+
#'
37
#' @inheritParams utf8::transform_lines_enc
48
#' @param ... Further arguments passed to `utf8::transform_lines_enc()`.
59
transform_code <- function(path, fun, verbose, ...) {
@@ -8,11 +12,15 @@ transform_code <- function(path, fun, verbose, ...) {
812
} else if (grepl("\\.Rmd$", path, ignore.case = TRUE)) {
913
utf8::transform_lines_enc(path, fun = partial(transform_rmd, transformer_fun = fun), ...)
1014
} else {
11-
stop("")
15+
stop(path, " is not an R or Rmd file")
1216
}
1317
}
1418

15-
#' Transform Rmd contents with a transformer function
19+
#' Transform Rmd contents
20+
#'
21+
#' Applies the supplied transformer function to code chunks identified within
22+
#' an Rmd file and recombines the resulting (styled) code chunks with the text
23+
#' chunks.
1624
#'
1725
#' @param lines A character vector of lines from an Rmd file
1826
#' @param transformer_fun A styler transformer function
@@ -26,7 +34,10 @@ transform_rmd <- function(lines, transformer_fun) {
2634
}
2735

2836

29-
#' Identify R and text chunks within an Rmd
37+
#' Identify chunks within Rmd contents
38+
#'
39+
#' Identifies the code and text chunks within an Rmd file, and returns these
40+
#' as a nested list.
3041
#'
3142
#' @param lines a character vector of lines from an Rmd file
3243
#'
@@ -54,7 +65,7 @@ identify_chunks <- function(lines) {
5465

5566
#' Get chunk pattern
5667
#'
57-
#' Determine a regex pattern for identifying R code chunks
68+
#' Determine a regex pattern for identifying R code chunks.
5869
#'
5970
#' @inheritParams identify_chunks
6071
get_knitr_pattern <- function(lines) {

man/get_knitr_pattern.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/identify_chunks.Rd

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

man/transform_code.Rd

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

man/transform_rmd.Rd

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

0 commit comments

Comments
 (0)