strwrapx                package:bbmle                R Documentation

_W_r_a_p _s_t_r_i_n_g_s _a_t _w_h_i_t_e _s_p_a_c_e _a_n_d + _s_y_m_b_o_l_s

_D_e_s_c_r_i_p_t_i_o_n:

     Extended (hacked) version of strwrap: wraps a string at whitespace
     and plus symbols

_U_s_a_g_e:

     strwrapx(x, width = 0.9 * getOption("width"), indent = 0, exdent = 0, prefix = "", simplify = TRUE, parsplit = "\n[ \t\n]*\n", wordsplit = "[ \t\n]")

_A_r_g_u_m_e_n_t_s:

       x: a character vector, or an object which can be converted to a
          character vector by 'as.character'.

   width: a positive integer giving the target column for wrapping
          lines in the output.

  indent: a non-negative integer giving the indentation of the first
          line in a paragraph.

  exdent: a non-negative integer specifying the indentation of
          subsequent lines in paragraphs.

  prefix: a character string to be used as prefix for each line.

simplify: a logical.  If 'TRUE', the result is a single character
          vector of line text; otherwise, it is a list of the same
          length as 'x' the elements of which are character vectors of
          line text obtained from the corresponding element of 'x'.
          (Hence, the result in the former case is obtained by
          unlisting that of the latter.)

parsplit: Regular expression describing how to split paragraphs

wordsplit: Regular expression decribing how to split words

_D_e_t_a_i_l_s:

     Whitespace in the input is destroyed.  Double spaces after periods
     (thought as representing sentence ends) are preserved.  Currently,
     possible sentence ends at line breaks are not considered
     specially.

     Indentation is relative to the number of characters in the prefix
     string.

_E_x_a_m_p_l_e_s:

     ## Read in file 'THANKS'.
     x <- paste(readLines(file.path(R.home("doc"), "THANKS")), collapse = "\n")
     ## Split into paragraphs and remove the first three ones
     x <- unlist(strsplit(x, "\n[ \t\n]*\n"))[-(1:3)]
     ## Join the rest
     x <- paste(x, collapse = "\n\n")
     ## Now for some fun:
     writeLines(strwrap(x, width = 60))
     writeLines(strwrap(x, width = 60, indent = 5))
     writeLines(strwrap(x, width = 60, exdent = 5))
     writeLines(strwrap(x, prefix = "THANKS> "))

     ## Note that messages are wrapped AT the target column indicated by
     ## 'width' (and not beyond it).
     ## From an R-devel posting by J. Hosking <jh910@juno.com>.
     x <- paste(sapply(sample(10, 100, rep=TRUE),
                function(x) substring("aaaaaaaaaa", 1, x)), collapse = " ")
     sapply(10:40,
            function(m)
            c(target = m, actual = max(nchar(strwrap(x, m)))))

