This function allows you to generate a tab book from a multitable and data. As with other functions, you can select the rows and columns you want to work with by subsetting the `dataset` you pass into the function.

tabBook_crunchtabs(
  multitable,
  dataset,
  weight = crunch::weight(dataset),
  append_default_wt = TRUE
)

Arguments

multitable

a `Multitable` object

dataset

CrunchDataset, which may be subset with a filter expression on the rows, and a selection of variables to use on the columns.

weight

a CrunchVariable that has been designated as a potential weight variable for `dataset`, or `NULL` for unweighted results. Default is the currently applied [`weight`]. Additionally, weights can be set on a per variable basis for json export only. To do so, specify the weight as either a list (which will be passed to `tabBookWeightSpec()`, or a data.frame that mimics the structure. See [`tabBookWeightSpec()`] for more details. generated from the `multitable`'s name if one is not supplied and the "xlsx" format is requested. Not required for "json" format export. of filters defined in the dataset.

append_default_wt

passed to [`tabBookWeightSpec()`] if `weight` is a list

Value

If "json" format is requested, the function returns an object of class `TabBookResult`, containing a list of `MultitableResult` objects, which themselves contain `CrunchCube`s. For single weight tabbook, the variables are always sorted in the order the server stores them in, but complex weights are sorted in the order of the data.frame given. If "xlsx" is requested, the function invisibly returns the filename (`file`, if specified, or the the autogenerated file name). If you request "json" and wish to access the JSON data underlying the `TabBookResult`, pass in a path for `file` and you will get a JSON file written there as well.

Details

By specifying a "json" `format`, instead of generating an Excel workbook, you'll get a TabBookResult object, containing nested CrunchCube results. You can then further format these and construct custom tab reports.

Tabbook pages are organized in the order the variables are stored by the server, unless complex weights are specified, in which case, the variables are sorted in the order of the weight specification dataset (like the one created by `tabBookWeightSpec()`).

Examples

if (FALSE) { m <- newMultitable(~ gender + age4 + marstat, data = ds) tabBook(m, ds, format = "xlsx", file = "wealthy-tab-book.xlsx", filter = "wealthy") book <- tabBook(m, ds) # Returns a TabBookResult tables <- prop.table(book, 2) }