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
2 changes: 1 addition & 1 deletion R/indent.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ compute_indent_indices <- function(pd,
)
trigger <- potential_triggers[needs_indention][1L]
if (is.na(trigger)) {
return(numeric(0))
return(numeric(0L))
}
start <- trigger + 1
if (is.null(token_closing)) {
Expand Down
2 changes: 1 addition & 1 deletion R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ transform_utf8_one <- function(path, fun, dry) {
# only write back when changed OR when there was a missing newline
new <- unclass(fun(file_with_info$text))
if (identical(new, "")) {
new <- character(0)
new <- character(0L)
}
identical_content <- identical(file_with_info$text, new)
identical <- identical_content && !file_with_info$missing_EOF_line_break
Expand Down
2 changes: 1 addition & 1 deletion R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ add_cache_block <- function(pd_nested) {
if (cache_is_activated()) {
pd_nested$block <- cache_find_block(pd_nested)
} else {
pd_nested$block <- rep(1, length(pd_nested$block))
pd_nested$block <- rep(1L, length(pd_nested$block))
}
pd_nested
}
Expand Down
8 changes: 4 additions & 4 deletions R/relevel.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ relocate_eq_assign_nest <- function(pd) {
#' @keywords internal
find_block_id <- function(pd) {
idx_eq_assign <- which(pd$token == "EQ_ASSIGN")
eq_belongs_to_block <- c(0, diff(idx_eq_assign) > 2)
eq_belongs_to_block <- c(0L, diff(idx_eq_assign) > 2L)

empty_seq <- rep(0, nrow(pd))
empty_seq[idx_eq_assign - 1] <- eq_belongs_to_block
empty_seq <- rep(0L, nrow(pd))
empty_seq[idx_eq_assign - 1L] <- eq_belongs_to_block
block_id <- cumsum(empty_seq)
block_id
}
Expand All @@ -216,7 +216,7 @@ relocate_eq_assign_one <- function(pd) {
idx_eq_assign <- which(pd$token == "EQ_ASSIGN")
eq_ind <- seq2(idx_eq_assign[1L] - 1L, last(idx_eq_assign) + 1L)
# initialize because wrap_expr_in_expr -> create_tokens -> requires it
pd$indent <- 0
pd$indent <- 0L
eq_expr <- pd[eq_ind, ] %>%
wrap_expr_in_expr() %>%
add_line_col_to_wrapped_expr() %>%
Expand Down
6 changes: 3 additions & 3 deletions R/rules-tokens.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ add_brackets_in_pipe_child <- function(pd) {
add_brackets_in_pipe_one <- function(pd, pos) {
next_non_comment <- next_non_comment(pd, pos)
rh_child <- pd$child[[next_non_comment]]
if (nrow(rh_child) < 2 && rh_child$token == "SYMBOL") {
if (nrow(rh_child) < 2L && rh_child$token == "SYMBOL") {
child <- pd$child[[next_non_comment]]
new_pos_ids <- create_pos_ids(child, 1, after = TRUE, n = 2L)
new_pos_ids <- create_pos_ids(child, 1L, after = TRUE, n = 2L)
new_pd <- create_tokens(
texts = c("(", ")"),
lag_newlines = rep(0L, 2),
lag_newlines = rep(0L, 2L),
spaces = 0L,
pos_ids = new_pos_ids,
token_before = c(child$token[1L], "'('"),
Expand Down
4 changes: 2 additions & 2 deletions R/transform-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ parse_transform_serialize_r_block <- function(pd_nested,
)
} else {
serialized_transformed_text <- map2(
c(0, find_blank_lines_to_next_expr(pd_nested)[-1L] - 1L),
c(0L, find_blank_lines_to_next_expr(pd_nested)[-1L] - 1L),
paste0(rep_char(" ", base_indention), pd_nested$text),
~ c(rep("", .x), .y)
) %>%
unlist(use.names = FALSE)
}
c(rep("", start_line - 1), serialized_transformed_text)
c(rep("", start_line - 1L), serialized_transformed_text)
}

#' Find the groups of expressions that should be processed together
Expand Down
6 changes: 3 additions & 3 deletions R/transform-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ transform_mixed <- function(lines, transformer_fun, filetype) {
chunks$r_chunks <- map(chunks$r_chunks, transform_mixed_non_empty,
transformer_fun = transformer_fun
)
map2(chunks$text_chunks, c(chunks$r_chunks, list(character(0))), c) %>%
map2(chunks$text_chunks, c(chunks$r_chunks, list(character(0L))), c) %>%
flatten_chr()
}

Expand Down Expand Up @@ -70,11 +70,11 @@ separate_chunks <- function(lines, filetype) {
r_raw_chunks <- identify_raw_chunks(lines, filetype = filetype)

r_chunks <- map2(
r_raw_chunks$starts, r_raw_chunks$ends, ~ lines[seq2(.x + 1, .y - 1)]
r_raw_chunks$starts, r_raw_chunks$ends, ~ lines[seq2(.x + 1L, .y - 1L)]
)

text_chunks <- map2(
c(1, r_raw_chunks$ends), c(r_raw_chunks$starts, length(lines)),
c(1L, r_raw_chunks$ends), c(r_raw_chunks$starts, length(lines)),
~ lines[seq2(.x, .y)]
)
list(r_chunks = r_chunks, text_chunks = text_chunks)
Expand Down
8 changes: 4 additions & 4 deletions R/utils-navigate-nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#' @export
next_non_comment <- function(pd, pos) {
if (length(pos) < 1 || is.na(pos) || pos >= nrow(pd)) {
return(integer(0))
return(integer(0L))
}
candidates <- seq2(pos + 1L, nrow(pd))
if (all(candidates %in% which(pd$token == "COMMENT"))) {
return(integer(0))
return(integer(0L))
}
setdiff(candidates, which(pd$token == "COMMENT"))[1L]
}
Expand All @@ -26,11 +26,11 @@ next_non_comment <- function(pd, pos) {
#' @rdname next_non_comment
previous_non_comment <- function(pd, pos) {
if (length(pos) < 1 || is.na(pos) || pos > nrow(pd)) {
return(integer(0))
return(integer(0L))
}
candidates <- seq2(1L, pos - 1L)
if (all(candidates %in% which(pd$token == "COMMENT"))) {
return(integer(0))
return(integer(0L))
}
last(setdiff(candidates, which(pd$token == "COMMENT")))
}
Expand Down
10 changes: 5 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ new_styler_df <- function(x) {
#' styler:::ensure_last_n_empty(letters)
#' styler:::ensure_last_n_empty(c(letters, "", "", ""))
#' @keywords internal
ensure_last_n_empty <- function(x, n = 1) {
ensure_last_n_empty <- function(x, n = 1L) {
if (all(x == "")) {
return("")
}
x <- c(x, "", "")
x <- x[seq(1, length(x) - which(rev(x) != "")[1L] + 1L)]
x <- x[seq(1L, length(x) - which(rev(x) != "")[1L] + 1L)]
c(x, rep("", n))
}

Expand All @@ -43,14 +43,14 @@ re_match <- function(text, pattern) {
length <- attr(match, "match.length")
end <- start + length - 1L
matchstr <- substring(text, start, end)
matchstr[start == -1] <- NA_character_
matchstr[start == -1L] <- NA_character_
res <- data.frame(stringsAsFactors = FALSE, .text = text, .match = matchstr)

gstart <- attr(match, "capture.start")
glength <- attr(match, "capture.length")
gend <- gstart + glength - 1L
groupstr <- substring(text, gstart, gend)
groupstr[gstart == -1] <- NA_character_
groupstr[gstart == -1L] <- NA_character_
dim(groupstr) <- dim(gstart)
res <- cbind(groupstr, res, stringsAsFactors = FALSE)

Expand All @@ -70,7 +70,7 @@ re_match <- function(text, pattern) {
#' @keywords internal
convert_newlines_to_linebreaks <- function(text) {
split <- strsplit(text, "\n", fixed = TRUE)
map(split, ~ if (identical(.x, character(0))) {
map(split, ~ if (identical(.x, character(0L))) {
""
} else {
.x
Expand Down
2 changes: 1 addition & 1 deletion man/ensure_last_n_empty.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.