This function takes a vector of strings and adds line breaks every n characters. Primarily built to be called internally by format_citation, this function has been made available as it can be useful in other contexts.

add_line_breaks(x, n = 50, html = FALSE)

Arguments

x

Either a string or a vector; if the vector is not of class character if will be coerced to one using as.character.

n

Numeric: The number of characters that should separate consecutive line breaks.

html

Logical: Should the function add HTML line breaks (<br>)? Defaults to FALSE, in which case the newline sequence is used instead (escape-n).

Value

Returns the input vector unaltered except for the addition of line breaks.

Details

Line breaks are only added between words, so the value of n is acutally a threshold value rather than being matched exactly.

Examples

file_location <- system.file(
  "extdata",
  "avian_ecology_bibliography.ris",
  package = "revtools")
x <- read_bibliography(file_location)
add_line_breaks(x$title)
#>  [1] "Modelling future scenarios to improve woodland\nlandscapes for birds in the Mediterranean"                                                                          
#>  [2] "Quantifying turnover in biodiversity of British breeding\nbirds"                                                                                                    
#>  [3] "Riparian tree cover enhances the resistance and stability\nof woodland bird communities during an extreme climatic\nevent"                                          
#>  [4] "Consequences of pinyon and juniper woodland reduction for\nwildlife in North America"                                                                               
#>  [5] "The biodiversity contribution of wood plantations\nContrasting the bird communities of Sweden's protected and\nproduction oak forests"                              
#>  [6] "The heterogeneity of wooded-agricultural landscape\nmosaics influences woodland bird community assemblages"                                                         
#>  [7] "Does the response of bird assemblages to fire mosaic\nproperties vary among spatial scales and foraging guilds?"                                                    
#>  [8] "Composition and structure of bird communities in\nvegetational gradients of Bodoquena Mountains, Western Brazil"                                                    
#>  [9] "Fruiting phenology as a triggering attribute of invasion\nprocess Do invasive species take advantage of seed\ndispersal service provided by native birds?"          
#> [10] "Trends in forest condition, threats and conservation\naction as derived from participatory monitoring in coastal\nKenya"                                            
#> [11] "Geotechnology-Based Modeling to Optimize Conservation\nof Forest Network in Urban Area"                                                                             
#> [12] "Effects of breeding habitat (woodland versus urban) and\nmetal pollution on the egg characteristics of great tits\n(Parus major)"                                   
#> [13] "Grassland birds demonstrate delayed response to\nlarge-scale tree removal in central North America"                                                                 
#> [14] "Birds as predators of cork and holm oak pests"                                                                                                                      
#> [15] "Evaluating the effectiveness of overstory cover as a\nsurrogate for bird community diversity and population trends"                                                 
#> [16] "Evolution of angiosperm seed disperser mutualisms The\ntiming of origins and their consequences for coevolutionary\ninteractions between angiosperms and frugivores"
#> [17] "Effects of dominant tree species on insectivorous birds\nbreeding in Mediterranean oak woodlands"                                                                   
#> [18] "Rural abandoned landscapes and bird assemblages winners\nand losers in the rewilding of a marginal mountain area (NW\nSpain)"                                       
#> [19] "The spatial diversity of bird communities in the middle\ntaiga of the Central Siberian Plateau"                                                                     
#> [20] "Relative importance of perch and facilitative effects on\nnucleation in tropical woodland in Malawi"