From 0cf809f84e93cf1e4040689b9f3d7f5e1f2dd04d Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Mon, 9 Dec 2024 13:51:52 -0600 Subject: [PATCH] remove unneeded conditional + default NULL op --- R/rstudioapi.R | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/R/rstudioapi.R b/R/rstudioapi.R index 1b3b9e2..68d803b 100644 --- a/R/rstudioapi.R +++ b/R/rstudioapi.R @@ -151,25 +151,20 @@ stream_selection_impl <- function(selection, context, pal, n_lines_orig, remaind if (identical(chunk, "")) {next} output_lines <- paste(output_lines, chunk, sep = "") n_lines <- nchar(gsub("[^\n]+", "", output_lines)) + 1 - if (n_lines_orig - n_lines > 0) { - output_padded <- - paste0( - output_lines, - paste0(rep("\n", n_lines_orig - n_lines + 1), collapse = "") - ) - } else { - output_padded <- paste(output_lines, "\n") - } + output_padded <- paste0( + output_lines, + paste0(rep("\n", max(n_lines_orig - n_lines + 1, 1)), collapse = "") + ) rstudioapi::modifyRange( selection$range, - output_padded %||% output_lines, + output_padded, context$id ) # there may be more lines in the output than there are in the range n_selection <- selection$range$end[[1]] - selection$range$start[[1]] - n_lines_res <- nchar(gsub("[^\n]+", "", output_padded %||% output_lines)) + n_lines_res <- nchar(gsub("[^\n]+", "", output_padded)) selection$range$end[["row"]] <- selection$range$start[["row"]] + n_lines_res })