Learn R Programming

formatters (version 0.5.0)

export_as_txt: Export a table-like object to plain (ASCII) text with page break

Description

This function converts x to a MatrixPrintForm object via matrix_form, paginates it via paginate, converts each page to ASCII text via toString, and emits the strings to file, separated by page_break.

Usage

export_as_txt(
  x,
  file = NULL,
  page_type = NULL,
  landscape = FALSE,
  pg_width = page_dim(page_type)[if (landscape) 2 else 1],
  pg_height = page_dim(page_type)[if (landscape) 1 else 2],
  font_family = "Courier",
  font_size = 8,
  lineheight = 1L,
  margins = c(top = 0.5, bottom = 0.5, left = 0.75, right = 0.75),
  paginate = TRUE,
  cpp = NA_integer_,
  lpp = NA_integer_,
  ...,
  hsep = default_hsep(),
  indent_size = 2,
  tf_wrap = paginate,
  max_width = NULL,
  colwidths = NULL,
  min_siblings = 2,
  nosplitin = character(),
  rep_cols = num_rep_cols(x),
  verbose = FALSE,
  page_break = "\\s\\n"
)

Value

if file is NULL, the total paginated and then concatenated string value, otherwise the file that was written.

Arguments

x

ANY. The table-like object to export. Must have an applicable matrix_form method.

file

character(1) or NULL. If non-NULL, the path to write a text file to containing the x rendered as ASCII text,

page_type

character(1). Name of a page type. See page_types. Ignored when pg_width and pg_height are set directly.

landscape

logical(1). Should the dimensions of page_type be inverted for landscape? Defaults to FALSE, ignored when pg_width and pg_height are set directly.

pg_width

numeric(1). Page width in inches.

pg_height

numeric(1). Page height in inches.

font_family

character(1). Name of a font family. An error will be thrown if the family named is not monospaced. Defaults to Courier.

font_size

numeric(1). Font size, defaults to 12.

lineheight

numeric(1). Line height, defaults to 1.

margins

numeric(4). Named numeric vector containing 'bottom', 'left', 'top', and 'right' margins in inches. Defaults to .5 inches for both vertical margins and .75 for both horizontal margins.

paginate

logical(1). Whether pagination should be performed, defaults to TRUE if page size is specified (including the default).

cpp

numeric(1) or NULL. Width in characters per page. if NA (the default, this is calculated automatically based on the specified page size). NULL indicates no horizontal pagination should occur.

lpp

numeric(1) or NULL. Lines per page. if NA (the default, this is calculated automatically based on the specified page size). NULL indicates no vertical pagination should occur.

...

Passed to individual methods.

hsep

character(1). Characters to repeat to create header/body separator line.

indent_size

numeric(1). Indent size in characters. Ignored when x is already a MatrixPrintForm object in favor of information there.

tf_wrap

logical(1). Should the texts for title, subtitle, and footnotes be wrapped?

max_width

integer(1), character(1) or NULL. Width that title and footer (including footnotes) materials should be word-wrapped to. If NULL, it is set to the current print width of the session (getOption("width")). If set to "auto", the width of the table (plus any table inset) is used. Ignored completely if tf_wrap is FALSE.

colwidths

numeric vector. Column widths (in characters) for use with vertical pagination.

min_siblings

numeric. Minimum sibling rows which must appear on either side of pagination row for a mid-subtable split to be valid. Defaults to 2.

nosplitin

character. List of names of sub-tables where page-breaks are not allowed, regardless of other considerations. Defaults to none.

rep_cols

numeric(1). Number of columns (not including row labels) to be repeated on every page. Defaults to 0

verbose

logical(1). Should additional informative messages about the search for pagination breaks be shown. Defaults to FALSE.

page_break

character(1). Page break symbol (defaults to outputting "\n\s").

Details

if x has an num_rep_cols method, the value returned by it will be used for rep_cols by default, if not, 0 will be used.

If x has an applicable do_mand_paginate method, it will be invoked during the pagination process.

Examples

Run this code
export_as_txt(basic_matrix_form(mtcars), pg_height = 5, pg_width = 4)

Run the code above in your browser using DataLab