Skip to content

Commit b347652

Browse files
WIP that breaks test
Attempt to use clear definitions for code line: * until immediately before transofmriong: \n characterizes line break, * map the previous definition to the styler definition. One line is one element. Can't simply paste0(...) %>% strplit("\n", fixed = TRUE) I think.
1 parent 688feff commit b347652

File tree

6 files changed

+224
-9
lines changed

6 files changed

+224
-9
lines changed

R/roxygen-examples-add-remove.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
#' @param roxygen Roxygen code examples that contains a dont* segment only.
44
#' @keywords internal
55
remove_dont_mask <- function(roxygen) {
6-
potential_pos <- c(3L, length(roxygen) - 1L)
7-
is_line_break_at_potential_pos <- which(roxygen[potential_pos] == "\n")
86
mask <- c(
9-
1L, 2L, length(roxygen), potential_pos[is_line_break_at_potential_pos]
7+
1L, 2L, if (roxygen[3] == "\n") 3L, last(which(roxygen == "}"))
108
) %>% sort()
119
list(
1210
code = roxygen[-mask], mask = paste(roxygen[seq2(1, 2)], collapse = "")

R/roxygen-examples-parse.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ post_parse_roxygen <- function(raw) {
3232
special <- substr(raw, 1, 1) == "%"
3333
len <- nchar(raw)
3434
newline_after <- substr(raw, len, len) == "\n"
35-
must_instert_linebreak_after <- which(
36-
(special & !newline_after) |
37-
(raw == "}" & (!(lead(substr(raw, 1, 1)) %in% c(",", "}", ")"))))
38-
)
35+
# must_instert_linebreak_after <- which(
36+
# (special & !newline_after) |
37+
# (raw == "}" & (!(lead(substr(raw, 1, 1)) %in% c(",", "}", ")"))))
38+
# )
39+
must_instert_linebreak_after <- integer(0)
3940
split <- reduce(must_instert_linebreak_after +
4041
seq(0L, length(must_instert_linebreak_after) - 1L),
4142
append, values = "\n", .init = raw

R/roxygen-examples.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ style_roxygen_code_example <- function(example, transformers) {
3535
#' @importFrom purrr map2 flatten_chr
3636
#' @keywords internal
3737
style_roxygen_code_example_segment <- function(one_dont, transformers) {
38-
one_dont <- remove_blank_lines(one_dont)
3938
if (length(one_dont) < 1L) return(character())
4039
dont_seqs <- find_dont_seqs(one_dont)
4140
split_segments <- split_roxygen_segments(one_dont, unlist(dont_seqs))
@@ -68,7 +67,6 @@ style_roxygen_example_snippet <- function(code_snippet,
6867
mask <- decomposed$mask
6968
}
7069
code_snippet <- post_parse_roxygen(code_snippet) %>%
71-
paste0(collapse = "\n") %>%
7270
parse_transform_serialize_r(transformers)
7371

7472
if (is_dont) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
#' Create a style guide
3+
#'
4+
#' @param reindention A list of parameters for regex re-indention, most
5+
#' conveniently constructed using [specify_reindention()].
6+
#' @examples
7+
#' # empty
8+
#'
9+
#'
10+
#' # two
11+
#'
12+
#'
13+
#'
14+
#'
15+
#' # more
16+
#' a <- 3
17+
#' # a comment
18+
#' \dontrun{
19+
#' x
20+
#'
21+
#' y # hi
22+
#'
23+
#' # more
24+
#'
25+
#' a <- 3
26+
#' }
27+
#' @importFrom purrr compact
28+
#' @export
29+
create_style_guide <- function(initialize = default_style_guide_attributes,
30+
line_break = NULL,
31+
space = NULL,
32+
token = NULL,
33+
indention = NULL,
34+
use_raw_indention = FALSE,
35+
reindention = tidyverse_reindention()) {
36+
lst(
37+
# transformer functions
38+
initialize = lst(initialize),
39+
line_break,
40+
space,
41+
token,
42+
indention,
43+
# transformer options
44+
use_raw_indention,
45+
reindention
46+
) %>%
47+
map(compact)
48+
}

tests/testthat/roxygen-examples-complete/13-empty-lines-in_tree

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
#' Create a style guide
3+
#'
4+
#' @param reindention A list of parameters for regex re-indention, most
5+
#' conveniently constructed using [specify_reindention()].
6+
#' @examples
7+
#'
8+
#' # empty
9+
#'
10+
#'
11+
#' # two
12+
#'
13+
#'
14+
#'
15+
#'
16+
#' # more
17+
#' a <- 3
18+
#' # a comment
19+
#' @examples
20+
#' \dontrun{
21+
#' x
22+
#'
23+
#' y # hi
24+
#'
25+
#' # more
26+
#'
27+
#' a <- 3
28+
#' }
29+
#'
30+
#' @importFrom purrr compact
31+
#' @export
32+
create_style_guide <- function(initialize = default_style_guide_attributes,
33+
line_break = NULL,
34+
space = NULL,
35+
token = NULL,
36+
indention = NULL,
37+
use_raw_indention = FALSE,
38+
reindention = tidyverse_reindention()) {
39+
lst(
40+
# transformer functions
41+
initialize = lst(initialize),
42+
line_break,
43+
space,
44+
token,
45+
indention,
46+
# transformer options
47+
use_raw_indention,
48+
reindention
49+
) %>%
50+
map(compact)
51+
}

0 commit comments

Comments
 (0)