Skip to content

Commit

Permalink
Make roxygen2 compatible with dev version of stringr
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jan 26, 2015
1 parent b4a294c commit e920f7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# roxygen2 4.1.0.9000

* The collate roclet falls back to `base::strwrap()` when generating the
collate field. This makes roxygen2 compatible with the next version of
stringr.

* New "vignette" roclet. This vignette automatically rebuilds all out of date
vignettes (#314).

Expand Down
26 changes: 18 additions & 8 deletions R/description.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cat.description <- function(field, value, file='') {
width <- 80
if (field %in% c("Collate")) {
# Individual lines
width <- 0
width <- 0L
} else if (field %in% c("Authors@R")) {
# No wrapping
width <- Inf
Expand All @@ -39,15 +39,25 @@ cat.description <- function(field, value, file='') {
}

# Determine whether a given field is too long and should be text-wrapped
wrap_field_if_necessary <- function(field, value, wrap.threshold) {
text <- simulate_formatted_text(field, value)
longest.line <- max(str_length(text))
wrap_field_if_necessary <- function(field, value, wrap.threshold = 80L) {

if (longest.line > wrap.threshold) {
text <- str_wrap(paste0(field, ": ", value), exdent = 4, width = wrap.threshold)
}
if (identical(wrap.threshold, 0L)) {
text <- paste0(field, ": ", value)
# 0 is a special case: this is only used for collate where we want
# one file name per line. stringr::str_wrap does paragraph wrapping
# which is not what we want
return(paste(strwrap(text, exdent = 4, width = 0), collapse = "\n"))
}

text <- simulate_formatted_text(field, value)
longest.line <- max(str_length(text))

return(text)
if (longest.line > wrap.threshold) {
text <- paste0(field, ": ", value)
text <- str_wrap(text, exdent = 4, width = wrap.threshold)
}

return(text)
}

# Simulate what was probably the user's intended field formatting
Expand Down

0 comments on commit e920f7c

Please sign in to comment.