Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,15 @@ add_terminal_token_after <- function(pd_flat) {
filter(terminal) %>%
arrange_pos_id()

new_tibble(list(
pos_id = terminals$pos_id,
token_after = lead(terminals$token, default = "")
),
nrow = nrow(terminals)
) %>%
left_join(pd_flat, ., by = "pos_id")
rhs <- new_tibble(
list(
pos_id = terminals$pos_id,
token_after = lead(terminals$token, default = "")
),
nrow = nrow(terminals)
)

left_join(pd_flat, rhs, by = "pos_id")
}

#' @rdname add_token_terminal
Expand All @@ -266,14 +268,15 @@ add_terminal_token_before <- function(pd_flat) {
filter(terminal) %>%
arrange_pos_id()

new_tibble(
rhs <- new_tibble(
list(
id = terminals$id,
token_before = lag(terminals$token, default = "")
),
nrow = nrow(terminals)
) %>%
left_join(pd_flat, ., by = "id")
)

left_join(pd_flat, rhs, by = "id")
}


Expand Down Expand Up @@ -351,13 +354,19 @@ nest_parse_data <- function(pd_flat) {
internal$child <- NULL

child$parent_ <- child$parent
joined <-
child %>%
nest_(., "child", setdiff(names(.), "parent_")) %>%
left_join(internal, ., by = c("id" = "parent_"))
nested <- joined
nested$child <- map2(nested$child, nested$internal_child, combine_children)
nested <- nested[, setdiff(names(nested), "internal_child")]

rhs <- nest_(child, "child", setdiff(names(child), "parent_"))

nested <- left_join(internal, rhs, by = c("id" = "parent_"))

children <- nested$child
for (i in seq_along(children)) {
new <- combine_children(children[[i]], nested$internal_child[[i]])
# Work around is.null(new)
children[i] <- list(new)
}
nested$child <- children
nested$internal_child <- NULL
nest_parse_data(nested)
}

Expand Down
5 changes: 2 additions & 3 deletions R/roxygen-examples-parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ emulate_rd <- function(roxygen) {
text <- roxygen2::roc_proc_text(
roxygen2::rd_roclet(),
paste(roxygen, collapse = "\n")
)[[1]]$get_section("examples") %>%
as.character() %>%
.[-1]
)[[1]]$get_section("examples")
text <- as.character(text)[-1]
text <- c(
if (grepl("^#'(\\s|\t)*@examples(\\s|\t)*$", roxygen[2])) "",
text
Expand Down
19 changes: 12 additions & 7 deletions R/transform-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,20 @@ parse_transform_serialize_r <- function(text,
transformers
)

text_out <- pd_nested %>%
split(pd_nested$block) %>%
unname() %>%
map2(find_blank_lines_to_next_block(pd_nested),
parse_transform_serialize_r_block,
pd_split <- unname(split(pd_nested, pd_nested$block))
pd_blank <- find_blank_lines_to_next_block(pd_nested)

text_out <- vector("list", length(pd_split))
for (i in seq_along(pd_split)) {
text_out[[i]] <- parse_transform_serialize_r_block(
pd_split[[i]],
pd_blank[[i]],
transformers = transformers,
base_indention = base_indention
) %>%
unlist()
)
}

text_out <- unlist(text_out)

verify_roundtrip(
text, text_out,
Expand Down