Skip to content

Commit

Permalink
Replace stringr::str_dup() with paste()/rep() (yihui#2186, yihu…
Browse files Browse the repository at this point in the history
…i#1549)

Co-authored-by: Yihui Xie <[email protected]>
  • Loading branch information
rich-iannone and yihui authored Oct 19, 2022
1 parent c5a1747 commit 1ce8286
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ print.block = function(x, ...) {
if (length(code) && !is_blank(code)) {
cat('\n ', stringr::str_pad(' R code chunk ', getOption('width') - 10L, 'both', '~'), '\n')
cat(one_string(' ', code), '\n')
cat(' ', stringr::str_dup('~', getOption('width') - 10L), '\n')
cat(' ', rep_str('~', getOption('width') - 10L), '\n')
}
cat(paste('##------', date(), '------##'), sep = '\n')
}
Expand Down Expand Up @@ -386,7 +386,7 @@ print.inline = function(x, ...) {
getOption('width') - 10L, 'both', '-'), '\n')
cat(sprintf(' %s:%s %s', x$location[, 1], x$location[, 2], x$code),
sep = '\n')
cat(' ', stringr::str_dup('-', getOption('width') - 10L), '\n')
cat(' ', rep_str('-', getOption('width') - 10L), '\n')
} else cat('inline R code fragments\n')
} else cat(' ordinary text without R code\n')
cat('\n')
Expand Down
3 changes: 3 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1075,3 +1075,6 @@ remove_urls = function(x) {
# regex adapted from https://dev.to/mattkenefick/regex-convert-markdown-links-to-html-anchors-f7j
gsub("(?<!`)\\[([^]]+)\\]\\(([^)]+)\\)(?!`)", "\\1", x, perl = TRUE)
}

# repeat a string for n times
rep_str = function(x, n, sep = '') paste(rep(x, n), collapse = sep)

0 comments on commit 1ce8286

Please sign in to comment.