Package 'tabxplor'

Title: User-Friendly Tables with Color Helpers for Data Exploration
Description: Make it easy to deal with multiple cross-tables in data exploration, by creating them, manipulating them, and adding color helpers to highlight important informations (differences from totals, comparisons between lines or columns, contributions to variance, confidence intervals, odds ratios, etc.). All functions are pipe-friendly and render data frames which can be easily manipulated. In the same time, time-taking operations are done with 'data.table' to go faster with big dataframes. Tables can be exported with formats and colors to 'Excel', plot and html.
Authors: Brice Nocenti [aut, cre]
Maintainer: Brice Nocenti <[email protected]>
License: GPL (>= 3)
Version: 1.3.0
Built: 2025-02-01 12:33:29 UTC
Source: https://github.com/bricenocenti/tabxplor

Help Index


subset method for class tabxplor_grouped_tab

Description

subset method for class tabxplor_grouped_tab

Usage

"x[i]  ;  x[i, j, ... , drop = TRUE]"

Arguments

x

A tabxplor_grouped_tab object.

i, j, ...

Indices

drop

For matrices and arrays. If TRUE the result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement.

Value

An object of class tabxplor_grouped_tab.


set sub-subset method for class tabxplor_grouped_tab

Description

set sub-subset method for class tabxplor_grouped_tab

Usage

"x[[...]] <- value"

Arguments

x

A tabxplor_grouped_tab object.

...

Indices

value

The new value.

Value

An object of class tabxplor_grouped_tab.


set subset method for class tabxplor_grouped_tab

Description

set subset method for class tabxplor_grouped_tab

Usage

"x[i] <- value  ;   x[i, j, ...] <- value"

Arguments

x

A tabxplor_grouped_tab object.

i, j, ...

Indices.

value

The new value.

Value

An object of class tabxplor_grouped_tab.


$ method for class tabxplor_fmt

Description

$ method for class tabxplor_fmt

Usage

## S3 method for class 'tabxplor_fmt'
x$name

Arguments

x

A tabxplor_fmt object.

name

The name of the field to extract.

Value

The relevant field of the tabxplor_fmt.


arrange method for class tabxplor_tab

Description

arrange method for class tabxplor_tab

Usage

## S3 method for class 'tabxplor_tab'
arrange(
  .data,
  ...,
  .by_group = TRUE,
  .by_totals = TRUE,
  .only_main_display = TRUE,
  .locale = NULL
)

Arguments

.data

A tibble of class tabxplor_tab.

...

<data-masking> Variables, or functions of variables. Use desc() to sort a variable in descending order.

.by_group

By default, will sort first by grouping variable. Set to FALSE to avoid this behaviour.

.by_totals

By default, will put totals at the end of their group. Set to FALSE to avoid this behaviour.

.only_main_display

By default, only the rows with the same display than the first row are arranged : if the first row of the group displays percentages, rows with n or pvalues are kept at the same place (typically, at the end of the group). Rows with the text "row_pct", "n" or "pvalue" in the row_var name are also kept at the same place. Set to FALSE to avoid this behaviour.

.locale

The locale to sort character vectors in.

Value

A tibble of class tabxplor__tab or tabxplor_grouped_tab.


Complete partial total rows

Description

Complete partial total rows

Usage

complete_partial_totals(tabs)

Arguments

tabs

A table or data.framate containting tabxplor_fmt columns.

Value

The table with completed total rows, total tables, and reference rows.


dplyr_col_modify method for class tabxplor_grouped_tab

Description

dplyr_col_modify method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
dplyr_col_modify(data, cols)

Arguments

data

A data frame.

cols

A named list used modify columns. A NULL value should remove an existing column.

Value

An object of class tabxplor_grouped_tab.


dplyr_reconstruct method for class tabxplor_grouped_tab

Description

dplyr_reconstruct method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
dplyr_reconstruct(data, template)

Arguments

data

A data frame.

template

Template to use for restoring attributes

Value

An object of class tabxplor_grouped_tab.


dplyr_row_slice method for class tabxplor_grouped_tab

Description

dplyr_row_slice method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
dplyr_row_slice(data, i, ...)

Arguments

data

A data frame.

i

A numeric or logical vector that indexes the rows of .data.

...

Future parameters.

Value

An object of class tabxplor_grouped_tab.


fct_recode helper to recode multiple variables

Description

fct_recode helper to recode multiple variables

Usage

fct_recode_helper(
  data,
  .cols = -where(is.numeric),
  name_in,
  name_out,
  style = c("mutate", "base"),
  reminder = TRUE,
  cat = TRUE
)

Arguments

data

The data frame.

.cols

<tidy-select> The variables to recode.

name_in

The name of the input data frame. Default to the expression given in data.

name_out

The name of the output data frame, if different from the input data frame.

style

Default is to use dplyr::mutate(). Set to base to use ⁠data$var <-⁠ style.

reminder

By default, a reminder of the syntax ("new" = "old") is printed. Set to FALSE to remove it.

cat

By default the result is written in the console if there are less than 6 variables, written in a temporary file and opened otherwise. Set to false to get a data frame with a character variable instead.

Value

When the number of variables is less than 5, a text in console as a side effect. With more than 5 variables, a temporary R file. A tibble with the recode text as a character variable is returned invisibly (or as main result if cat = TRUE).


Create a vector of class formatted numbers

Description

fmt vectors, of class tabxplor_fmt, powers tabxplor and tab tibbles. As a record, they stores all data necessary to calculate percentages, Chi2 metadata or confidence intervals, but also to format and color the table to help the user read it. You can access this data with vctrs::field, or change it with vctrs:field<-. A fmt vector have 13 fields : n, digits, display, wn, pct, mean, diff, ctr, var, ci, in_totrow, in_tottab, in_refrow. Other arguments are attributes, attached not to each value, but to the whole vector, like type, totcol or color. You can get them with attr and modify them with attr<-. Special functions listed below are made to facilitate programming with with tabxplor formatted numbers. taxplfmt vectors can use all standard operations, like +, -, sum(), or c(), using vctrs.

Usage

fmt(
  n = integer(),
  type = "n",
  digits = rep(0L, length(n)),
  display = dplyr::case_when(type == "mean" ~ "mean", type %in% c("row", "col", "all",
    "all_tabs") ~ "pct", TRUE ~ "n"),
  wn = rep(NA_real_, length(n)),
  pct = rep(NA_real_, length(n)),
  mean = rep(NA_real_, length(n)),
  diff = rep(NA_real_, length(n)),
  ctr = rep(NA_real_, length(n)),
  var = rep(NA_real_, length(n)),
  ci = rep(NA_real_, length(n)),
  rr = rep(NA_real_, length(n)),
  or = rep(NA_real_, length(n)),
  in_totrow = rep(FALSE, length(n)),
  in_tottab = rep(FALSE, length(n)),
  in_refrow = rep(FALSE, length(n)),
  comp_all = NA,
  ref = "",
  ci_type = "",
  col_var = "",
  totcol = FALSE,
  refcol = FALSE,
  color = ""
)

is_fmt(x)

get_num(x)

set_num(x, value)

get_type(x, ...)

set_type(x, type)

is_totrow(x, ...)

as_totrow(x, in_totrow = TRUE)

is_tottab(x, ...)

as_tottab(x, in_tottab = TRUE)

set_display(x, value)

is_totcol(x, ...)

as_totcol(x, totcol = TRUE)

is_refrow(x, ...)

as_refrow(x, in_refrow = TRUE)

get_comp_all(x, replace_na = TRUE)

set_comp_all(x, comp_all = FALSE)

get_ref_type(x, ...)

set_diff_type(x, ref)

get_ci_type(x, ...)

set_ci_type(x, ci_type)

get_col_var(x, ...)

set_col_var(x, col_var)

is_refcol(x, ...)

as_refcol(x, refcol = TRUE)

get_color(x, ...)

set_color(x, color)

get_digits(x)

set_digits(x, value)

Arguments

n

The underlying count, as an integer vector of length n(). It is used to calculate confidence intervals.

type

The type of the column, which defines the type of background calculation to be made (as a single string, since it's not a field but an attribute) :

  • "n": counts

  • "mean": mean column (from numeric variables)

  • "row": row percentages

  • "col": column percentages

  • "all": frequencies by subtable/group (i.e. by tab_vars)

  • "all_tabs": frequencies for the whole table

digits

The number of digits, as an integer, or an integer vector the length of n.

display

The display type : the name of the field you want to show when printing the vector. Among "n", "wn", "pct", "diff", "ctr", "mean", "var", "ci", "pct_ci" (percentages with visible confidence interval), "mean_ci" (means with visible confidence interval). As a single string, or a character vector the length of n.

wn

The underlying weighted counts, as a double vector the length of n. It is used in certain operations on fmt, like means.

pct

The percentages, as a double vector the length of n. Calculate with tab_pct.

mean

The means, as a double vector the length of n.

diff

The differences (from totals or first cells), as a double vector the length of n. Used to set colors for means and row or col percentages. Calculate with tab_pct.

ctr

The contributions of cells to (sub)tables variances, as a double vector the length of n. Used to print colors when color = "contrib". The mean contribution of each (sub)table is written on total rows (then, colors don't print well without total rows). Calculate with tab_chi2.

var

The cells variances, as a double vector the length of n. Used with type = "mean" to calculate confidence intervals. Calculate with tab_plain.

ci

The confidence intervals, as a double vector the length of n. Used to print colors ("diff_ci", "after_ci"). Calculate with tab_ci.

rr

The relative risk, as a double vector the length of n.

or

The odds ratio or relative risk ratio, as a double vector the length of n.

in_totrow

TRUE when the cell is part of a total row

in_tottab

TRUE when the cell is part of a total table

in_refrow

TRUE when the cell is part of a reference row (cf. ref)

comp_all

FALSE when the comparison level is the subtable/group, TRUE when it is the whole table

ref

The type of difference of the vector. Cf. tab.

ci_type

The type of confidence intervals of the vector (calculate with tab_ci) :

  • "" or "no": no ci have been calculated

  • "cell": absolute confidence intervals of cells percentages.

  • "diff": confidence intervals of the difference between a cell and the relative total cell (or relative first cell when ref = "first").

  • "auto": "diff" for means and row/col percentages, "cell" for frequencies ("all", "all_tabs").

col_var

The name of the col_var used to calculate the vector

totcol

TRUE when the vector is a total column

refcol

TRUE when the vector is a reference column

color

The type of color to print :

  • "no": no colors are printed.

  • "diff": color percentages and means based on cells differences from totals (or from first cells when ref = "first").

  • "diff_ci": color pct and means based on cells differences from totals or first cells, removing coloring when the confidence interval of this difference is higher than the difference itself.

  • "after_ci": idem, but cut off the confidence interval from the difference first.

  • "contrib": color cells based on their contribution to variance (except mean columns, from numeric variables).

x

The object to test, to get a field in, or to modify.

value

The value you want to inject in some fmt vector's vctrs::field or attribute using a given "set" function.

...

Used in methods to add arguments in the future.

replace_na

By default, get_comp_all takes NA in comparison level to be a FALSE (=comparison at subtables/groups level). Set to FALSE to avoid this behavior.

Value

A vector of class tabxplor_fmt.

A logical vector.

A double vector.

A modified fmt vector.

A character vector with the vectors type.

A modified fmt vector.

A logical vector with the fmt vectors totrow field.

A modified fmt vector with totrow field changed.

A logical vector with the fmt vectors tottab field.

A modified fmt vector with tottab field changed.

The entered objects, with all fmt vectors with the wanted display.

A logical vector with the fmt vectors totcol attribute.

A modified fmt vector with totcol attribute changed.

A logical vector with the fmt vectors in_refrow field

A modified fmt vector with in_refrom field changed.

A modified fmt vector with comp attribute changed.

A logical vector with the fmt vectors type attributes

A modified fmt vector.

A logical vector with the fmt vectors ci_type attributes

A modified fmt vector.

A logical vector with the fmt vectors col_var attributes

A modified fmt vector.

A logical vector with the fmt vectors is_refcol attributes

A modified fmt vector.

A logical vector with the fmt vectors color attributes

A modified fmt vector.

Functions

  • is_fmt(): a test function for class fmt.

  • get_num(): get the currently displayed field

  • set_num(): set the currently displayed field (not changing display type)

  • get_type(): get types of fmt columns (at fmt level or tab level)

  • set_type(): set the column type attribute of a fmt vector

  • is_totrow(): test function to detect cells in total rows (at fmt level or tab level)

  • as_totrow(): set the "in_totrow" field (belong to total row)

  • is_tottab(): test function to detect cells in total tables (at fmt level or tab level)

  • as_tottab(): set the "in_tottab" field (belong to total table)

  • set_display(): set the "display" vctrs::field of a fmt vector, or of all of them in the whole tibble.

  • is_totcol(): test function for total columns (at fmt level or tab level)

  • as_totcol(): set the "totcol" attribute of a fmt vector

  • is_refrow(): test function to detect cells in reference rows (at fmt level or tab level)

  • as_refrow(): set the "in_refrow" field (belong to reference row)

  • get_comp_all(): get comparison level of fmt columns

  • set_comp_all(): set the comparison level attribute of a fmt vector

  • get_ref_type(): get differences type of fmt columns (at fmt level or tab level)

  • set_diff_type(): set the differences type attribute of a fmt vector

  • get_ci_type(): get confidence intervals type of fmt columns (at fmt level or tab level)

  • set_ci_type(): set the confidence intervals type attribute of a fmt vector

  • get_col_var(): get names of column variable of fmt columns (at fmt level or tab level)

  • set_col_var(): set the "col_var" attribute of a fmt vector

  • is_refcol(): test function for reference columns (at fmt level or tab level)

  • as_refcol(): set the "ref_col" attribute of a fmt vector

  • get_color(): get color (at fmt level or tab level)

  • set_color(): set the "color" attribute of a fmt vector

  • get_digits(): get the "digits" field

  • set_digits(): set the "digits" field

Examples

library(dplyr)

f <- fmt(n = c(7, 19, 2), type = "row", pct = c(0.25, 0.679, 0.07))
f

# To get the currently displayed field :
get_num(f)

# To modify the currently displayed field :
set_num(f, c(1, 0, 0))


# See all the underlying fields of a fmt vector (a data frame with a number of rows
#  equal to the length of the vector) :
vctrs::vec_data(f)

# To get the numbers of digits :
vctrs::field(f, "digits")
f$digits

# To get the count :
vctrs::field(f, "n")
f$n

# To get the display :
vctrs::field(f, "display")
f$display

# To modify a field, you can use `dplyr::mutate` on the fmt vector,
# referring to the names of the columns of the underlying data.frame (`vctrs::vec_data`) :
vctrs::`field<-`(f, "pct", c(1, 0, 0))
mutate(f, pct = c(1, 0, 0))

# See all the attributes of a fmt vector :
attributes(f)

# To modify the "type" attribute of a fmt vector :
set_type(f, "col")

# To modify the "color" attribute of a fmt vector :
set_color(f, "contrib")




tabs <- tab(starwars, sex, hair_color, gender, na = "drop", pct = "row",
            other_if_less_than = 5)

# To identify the total columns, and work with them :
is_totcol(tabs)
tabs %>% mutate(across(where(is_totcol), ~ "total column"))

# To identify the total rows, and work with them :
is_totrow(tabs)
tabs %>%
  mutate(across(
    where(is_fmt),
    ~ if_else(is_totrow(.), true = "into_total_row", false = "normal_cell")
  ))

# To identify the total tables, and work with them :
tottabs <- is_tottab(tabs)
tabs %>% tibble::add_column(tottabs) %>%
  mutate(total = if_else(tottabs, "part of a total table", "normal cell"))

# To access the displayed numbers, as numeric vectors :
tabs %>% mutate(across(where(is_fmt), get_num))

# To access the displayed numbers, as character vectors (without colors) :
tabs %>% mutate(across(where(is_fmt), format))

# To access the (non-displayed) differences of the cells percentages from totals :
tabs %>% mutate(across(where(is_fmt), ~ vctrs::field(., "diff")))


# To do more complex operations, like creating a new column with standard deviation and
# print it with 2 decimals, use `dplyr::mutate` on all the fmt columns of a table :

tab_num(forcats::gss_cat, race, c(age, tvhours), marital, digits = 1L, comp = "all") |>
  dplyr::mutate(dplyr::across( #Mutate over the whole table.
    c(age, tvhours),
    ~ dplyr::mutate(.,         #Mutate over each fmt vector's underlying data.frame.
                    var     = sqrt(var),
                    display = "var",
                    digits  = 2L) |>
      set_color("no"),
    .names = "{.col}_sd"
  ))

Get HTML Color Code of a fmt vector

Description

Get HTML Color Code of a fmt vector

Usage

fmt_get_color_code(x, type = "text", theme = "light", html_24_bit = NULL)

Arguments

x

The fmt vector to get the html color codes from.

type

The style type in set_color_style and get_color_style, "text" to color the text, "bg" to color the background.

theme

For set_color_style and get_color_style, is your console or html table background "light" or "dark" ? Default to RStudio theme.

html_24_bit

Use 24bits colors palettes for html tables : set to "green_red" or "blue_red". Only with mode = "color_code" (not mode = "crayon") and ⁠theme = "light⁠. Default to getOption("tabxplor.color_html_24_bit").

Value

A character vector with html color codes, of the length of the initial vector.

Examples

tabs <- tab(forcats::gss_cat, race, marital, pct = "row", color = "diff")
dplyr::mutate(tabs, across(where(is_fmt), fmt_get_color_code))

Print method for class tabxplor_fmt

Description

Print method for class tabxplor_fmt

Usage

## S3 method for class 'tabxplor_fmt'
format(x, ..., html = FALSE, na = NA, special_formatting = FALSE)

Arguments

x

A fmt object.

...

Other parameters.

html

Should html tags be added (to print confidence intervals as subscripts) ?

na

How NAs should be printed. Default to NA.

special_formatting

Set to TRUE to print more verbose results, like indicating which is the reference row or col for differences.

Value

The fmt printed in a character vector.


Get confidence intervals type of fmt columns

Description

Get confidence intervals type of fmt columns

Usage

## S3 method for class 'data.frame'
get_ci_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A character vector with the ci_type attributes.


Get confidence intervals type of fmt columns

Description

Get confidence intervals type of fmt columns

Usage

## Default S3 method:
get_ci_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the ci_type attribute.


Get confidence intervals type of fmt columns

Description

Get confidence intervals type of fmt columns

Usage

## S3 method for class 'tabxplor_fmt'
get_ci_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the ci_type attribute.


Get names of column variable of fmt columns

Description

Get names of column variable of fmt columns

Usage

## S3 method for class 'data.frame'
get_col_var(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A character vector with the col_var attributes.


Get names of column variable of fmt columns

Description

Get names of column variable of fmt columns

Usage

## Default S3 method:
get_col_var(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the col_var attribute.


Get names of column variable of fmt columns

Description

Get names of column variable of fmt columns

Usage

## S3 method for class 'tabxplor_fmt'
get_col_var(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the col_var attribute.


Get color

Description

Get color

Usage

## S3 method for class 'data.frame'
get_color(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A character vector with the color attributes.


Get color

Description

Get color

Usage

## Default S3 method:
get_color(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the color attribute.


Get color

Description

Get color

Usage

## S3 method for class 'tabxplor_fmt'
get_color(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the color attribute.


Get differences type of fmt columns

Description

Get differences type of fmt columns

Usage

## S3 method for class 'data.frame'
get_ref_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A character vector with the ref attribute.


Get differences type of fmt columns

Description

Get differences type of fmt columns

Usage

## Default S3 method:
get_ref_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the ref attribute.


Get differences type of fmt columns

Description

Get differences type of fmt columns

Usage

## S3 method for class 'tabxplor_fmt'
get_ref_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the ref attribute.


Get types of fmt columns

Description

Get types of fmt columns

Usage

## S3 method for class 'data.frame'
get_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A character vector with the data.frame column's types.


Get types of fmt columns

Description

Get types of fmt columns

Usage

## Default S3 method:
get_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

An empty character vector.


Get types of fmt columns

Description

Get types of fmt columns

Usage

## S3 method for class 'tabxplor_fmt'
get_type(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single string with the vector's type.


group_by method for class tabxplor_tab

Description

group_by method for class tabxplor_tab

Usage

## S3 method for class 'tabxplor_tab'
group_by(.data, ..., .add = FALSE, .drop = dplyr::group_by_drop_default(.data))

Arguments

.data

A tibble of class tabxplor_tab.

...

Variables or computations to group by.

.add

When FALSE, the default, group_by() will override existing groups. To add to the existing groups, use .add = TRUE.

.drop

Drop groups formed by factor levels that don't appear in the data? The default is TRUE except when .data has been previously grouped with .drop = FALSE.

Value

A tibble of class tabxplor_grouped_tab.


Test function for reference columns

Description

Test function for reference columns

Usage

## S3 method for class 'data.frame'
is_refcol(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A character vector with the ref_col attributes.


Test function for reference columns

Description

Test function for reference columns

Usage

## Default S3 method:
is_refcol(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the ref_col attribute.


Test function for reference columns

Description

Test function for reference columns

Usage

## S3 method for class 'tabxplor_fmt'
is_refcol(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single character with the ref_col attribute.


Test function to detect cells in reference rows

Description

Test function to detect cells in reference rows

Usage

## S3 method for class 'data.frame'
is_refrow(x, ..., partial = TRUE)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

partial

Should partial reference rows be counted as reference rows ? Default to FALSE.

Value

A list of logical vectors with the in_refrow fields.


Test function to detect cells in reference rows

Description

Test function to detect cells in reference rows

Usage

## Default S3 method:
is_refrow(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A logical vector with FALSE, the length of x.


Test function to detect cells in reference rows

Description

Test function to detect cells in reference rows

Usage

## S3 method for class 'tabxplor_fmt'
is_refrow(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A logical vector with the in_refrow field.


Test function for total columns

Description

Test function for total columns

Usage

## S3 method for class 'data.frame'
is_totcol(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A logical vector, with the data.frame column's totcol attributes.


Test function for total columns

Description

Test function for total columns

Usage

## Default S3 method:
is_totcol(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single logical vector with the totcol attribute


Test function for total columns

Description

Test function for total columns

Usage

## S3 method for class 'tabxplor_fmt'
is_totcol(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A single logical vector with the totcol attribute


Test function to detect cells in total rows

Description

Test function to detect cells in total rows

Usage

## S3 method for class 'data.frame'
is_totrow(x, ..., partial = FALSE)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

partial

Should partial total rows be counted as total rows ? Default to FALSE.

Value

A list of logical vectors, with the data.frame column's totrow fields.


Test function to detect cells in total rows

Description

Test function to detect cells in total rows

Usage

## Default S3 method:
is_totrow(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A logical vector with FALSE.


Test function to detect cells in total rows

Description

Test function to detect cells in total rows

Usage

## S3 method for class 'tabxplor_fmt'
is_totrow(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A logical vector with the totrow field.


Test function to detect cells in total tables

Description

Test function to detect cells in total tables

Usage

## S3 method for class 'data.frame'
is_tottab(x, ..., partial = FALSE)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

partial

Should partial total tabs be counted as total tabs ? Default to FALSE.

Value

A list of logical vectors, with the data.frame column's tottab fields.


Test function to detect cells in total tables

Description

Test function to detect cells in total tables

Usage

## Default S3 method:
is_tottab(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A logical vector with FALSE.


Test function to detect cells in total tables

Description

Test function to detect cells in total tables

Usage

## S3 method for class 'tabxplor_fmt'
is_tottab(x, ...)

Arguments

x

The object to test, to get a field in, or to modify.

...

Used in methods to add arguments in the future.

Value

A logical vector with the tottab field.


Crosstables

Description

Crosstables

Usage

jmvtab(
  data,
  row_vars = NULL,
  col_vars = NULL,
  tab_vars = NULL,
  wt = NULL,
  pct = "no",
  color = "no",
  chi2 = TRUE,
  OR = "no",
  na = "keep",
  lvs = "all",
  other_if_less_than = 0,
  cleannames = TRUE,
  ref = "auto",
  ref2 = "first",
  comp = "tab",
  ci = "auto",
  conf_level = 0.95,
  ci_print = "ci",
  totaltab = "line",
  wrap_rows = 35,
  wrap_cols = 15,
  display = "auto",
  add_n = TRUE,
  add_pct = FALSE,
  subtext = "",
  digits = 0
)

Arguments

data

A data.frame.

row_vars

The row variable, which will be printed with one level per line. If numeric, it will be converted to factor.

col_vars

One column is printed for each level of each column variable. For numeric variables means are calculated, in a single column.

tab_vars

One subtable is made for each combination of levels of the tab variables. All tab variables are converted to factor. Leave empty to make a simple table.

wt

A weight variable, of class numeric. Leave empty for unweighted results.

pct

The type of percentages to calculate :

  • "row": row percentages.

  • "col": column percentages.

  • "all": frequencies for each subtable/group, if there is tab_vars.

  • "all_tabs": frequencies for the whole (set of) table(s).

color

The type of colors to print, as a single string. Vectorised over row_vars.

  • "no": by default, no colors are printed.

  • "diff": color percentages and means based on cells differences from totals (or from first cells when ref = "first").

  • "diff_ci": color pct and means based on cells differences from totals or first cells, removing coloring when the confidence interval of this difference is higher than the difference itself.

  • "after_ci": idem, but cut off the confidence interval from the difference first.

  • "contrib": color cells based on their contribution to variance (except mean columns, from numeric variables).

  • "OR": for pct == "col" or pct == "row", color based on odds ratios (or relative risks ratios)

chi2

Set to TRUE to make a Chi2 and add summary stats. Also useful to color cells based on their contribution to variance.

OR

With pct = "row" or pct = "col", calculate and print odds ratios (for binary variables) or relative risks ratios (for variables with 3 levels or more).

  • "no": by default, no OR are calculated.

  • "OR": print OR (instead of percentages).

  • "OR_pct": print OR, with percentages in bracket.

na

The policy to adopt with missing values. It must be a single string.

  • na = "keep": by default, prints NA's as explicit "NA" level.

  • na = "drop": removes NA levels before making each table (tabs made with different column variables may have a different number of observations, and won't exactly have the same total columns).

lvs

The levels of col_vars to keep.

  • "all": by default, all levels are kept.

  • "first": only keep the first level of each col_vars

  • "auto": keep the first level when col_var is only two levels, keep all levels otherwise.

other_if_less_than

When set to a positive integer, levels with less count than that will be merged into an "Others" level.

cleannames

By default, clean levels names, by removing prefix numbers like "1-", and text in parenthesis. Set to FALSE to avoid this behaviour.

ref

The reference cell to calculate differences and ratios (used to print colors) :

  • "auto": by default, cell difference from the corresponding total (rows or cols depending on pct = "row" or pct = "col") is used for diff ; cell ratio from the first line (or col) is use for OR (odds ratio/relative risks ratio).

  • "tot": totals are always used.

  • "first": calculate cell difference or ratio from the first cell of the row or column (useful to color temporal developments).

  • n: when ref is an integer, the nth row (or column) is used for comparison.

  • "regex": when ref is a string, it it used as a regular expression, to match with the names of the rows (or columns). Be precise enough to match only one column or row, otherwise you get a warning message.

  • "no": not use ref and not calculate diffs to gain calculation time.

ref2

A second reference cell is needed to calculate odds ratios (or relative risks ratios). The first cell of the row or column is used by default. See ref for the full list of possible values.

comp

The comparison level : by subtables/groups, or for the whole table.

ci

The type of confidence intervals to calculate, passed to tab_ci.

  • "cell": absolute confidence intervals of cells percentages.

  • "diff": confidence intervals of the difference between a cell and the relative total cell (or relative first cell when ref = "first").

  • "auto": ci = "diff" for means and row/col percentages, ci = "cell" for frequencies ("all", "all_tabs").

By default, for percentages, with ci = "cell" Wilson's method is used, and with ci = "diff" Wald's method along Agresti and Caffo's adjustment. Means use classic method.

conf_level

The confidence level, as a single numeric between 0 and

  1. Default to 0.95 (95\

ci_print

By default confidence interval are printed with the interval display. Set to "moe" to use pct +- moe instead.

totaltab

The total table, if there are subtables/groups (i.e. when tab_vars is provided). Vectorised over row_vars.

  • "line": by default, add a general total line (necessary for calculations with comp = "all")

  • "table": add a complete total table (i.e. row_var by col_vars without tab_vars).

  • "no": not to draw any total table.

wrap_rows

By default, rownames are wrapped when larger than 30 characters.

wrap_cols

By default, colnames are wrapped when larger than 12 characters.

display

The information to display in the table.

add_n

For pct = "row" or pct = "col", set to FALSE not to add another column or row with unweighted counts (n).

add_pct

Set to TRUE to add a column with the frequencies of the row variable (for pct = "row") or a row with the frequencies of the column variable (for pct = "col")

subtext

A character vector to print rows of legend under the table.

digits

The number of digits to print, as a single integer, or an integer vector the same length as col_vars.

Value

A results object containing:

results$html_table a html
results$chi2_table a table
results$plot an image

Tables can be converted to data frames with asDF or as.data.frame. For example:

results$chi2_table$asDF

as.data.frame(results$chi2_table)


Print a tabxplor table in html

Description

Print a tabxplor table in html

Usage

kable_tabxplor_style(
  tabs,
  caption = knitr::opts_current$get("tab.cap"),
  theme = c("light", "dark"),
  total_in_bold = TRUE,
  all_column_borders = FALSE,
  html_font = NULL,
  full_width = FALSE,
  wrap_rows = 35,
  wrap_cols = 15,
  whitespace_only = TRUE,
  subtext = "",
  ...
)

Arguments

tabs

A data.frame.

caption

The table caption. For formatting, you need to use a css with ⁠caption{}⁠in rmarkdown.

theme

By default, a white table with black text, Set to "dark" for a black table with white text.

total_in_bold

Should rows and cols with "Total" string be set in bold ?

all_column_borders

Put a vertical border around each column ?

html_font

A string for HTML css font. By default, it uses '"DejaVu Sans", "Arial", arial, helvetica, sans-serif'. Set another default by setting options("tabxplor.kable_html_font" = ).

full_width

A TRUE or FALSE variable controlling whether the HTML table should have the preferable format for full_width. If not specified, a HTML table will have full width by default but this option will be set to FALSE for a LaTeX table.

wrap_rows

By default, rownames are wrapped when larger than 30 characters.

wrap_cols

By default, colnames are wrapped when larger than 12 characters.

whitespace_only

Set to FALSE to wrap also on non whitespace characters.

subtext

A character vector to print rows of legend under the table.

...

Other arguments to pass to kableExtra::kable_styling.

Value

A html table (opened in the viewer in RStudio). Differences from totals, confidence intervals, contribution to variance, and unweighted counts, are available in an html tooltip at cells hover.

Examples

tabs <- tibble::tibble(nm      = c("First", "Second", "Total"),
                       column1 = c(1, 2, 3),
                       column2 = c(4, 5, 6)                    )
kable_tabxplor_style(tabs)

mutate method to access vctrs::fields of tabxplor_fmt vectors

Description

mutate method to access vctrs::fields of tabxplor_fmt vectors

Usage

## S3 method for class 'tabxplor_fmt'
mutate(.data, ...)

Arguments

.data

A tabxplor_fmt column.

...

Name-value pairs. The name gives the name of the column in the output (do not change it).

The value can be:

  • A vector of length 1, which will be recycled to the correct length.

  • A vector the same length as the current group (or the whole data frame if ungrouped).

Value

An object of class tabxplor_fmt.


A constructor for class tabxplor_tab

Description

A constructor for class tabxplor_tab

Usage

new_tab(
  tabs = tibble::tibble(),
  subtext = "",
  chi2 = tibble::tibble(tables = character(), pvalue = double(), df = integer(), cells =
    integer(), variance = double(), count = integer()),
  ...,
  class = character()
)

new_grouped_tab(
  tabs = tibble::tibble(),
  groups,
  subtext = "",
  chi2 = tibble::tibble(tables = character(), pvalue = double(), df = integer(), cells =
    integer(), variance = double(), count = integer()),
  ...,
  class = character()
)

Arguments

tabs

A table, stored into a tibble data.frame. It is generally made with tab, tab_many or tab_plain.

subtext

A character vector to print legend lines under the table.

chi2

A tibble storing information about pvalues and variances, to fill with tab_chi2.

...

Needed to implement subclasses.

class

Needed to implement subclasses.

groups

The grouping data.

Value

A tibble of class tabxplor_tab.

A tibble of class tabxplor_grouped_tab.


Print Chi2 tables columns

Description

Print Chi2 tables columns

Usage

## S3 method for class 'tab_chi2_fmt'
pillar_shaft(x, ...)

Arguments

x

A fmt object.

...

Other parameter.

Value

A Chi2 table column printed in a pillar.


Pillar_shaft method to print class fmt in a tibble column

Description

Pillar_shaft method to print class fmt in a tibble column

Usage

## S3 method for class 'tabxplor_fmt'
pillar_shaft(x, ...)

Arguments

x

A fmt object.

...

Other parameter.

Value

A fmt printed in a pillar.


Printing method for class tabxplor_grouped_tab

Description

Printing method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
print(
  x,
  width = NULL,
  ...,
  n = 100,
  max_extra_cols = NULL,
  max_footer_lines = NULL,
  min_row_var = 30,
  get_text = FALSE
)

Arguments

x

Object to format or print.

width

Width of text output to generate.

...

Passed on to tbl_format_setup().

n

Number of rows to show.

max_extra_cols

Number of extra columns to print abbreviated information for, if the width is too small for the entire tibble.

max_footer_lines

Maximum number of footer lines.

min_row_var

Minimum number of characters for the row variable. Default to 30.

get_text

Set to TRUE to get the text as a character vector instead of a printed output.

Value

A printed grouped table.


Printing method for class tabxplor_tab

Description

Printing method for class tabxplor_tab

Usage

## S3 method for class 'tabxplor_tab'
print(
  x,
  width = NULL,
  ...,
  n = 100,
  max_extra_cols = NULL,
  max_footer_lines = NULL,
  min_row_var = 30,
  get_text = FALSE
)

Arguments

x

Object to format or print.

width

Width of text output to generate.

...

Passed on to tbl_format_setup().

n

Number of rows to show.

max_extra_cols

Number of extra columns to print abbreviated information for, if the width is too small for the entire tibble.

max_footer_lines

Maximum number of footer lines.

min_row_var

Minimum number of characters for the row variable. Default to 30.

get_text

Set to TRUE to get the text as a character vector instead of a printed output.

Value

A printed table.


relocate method for class tabxplor_grouped_tab

Description

relocate method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
relocate(.data, ...)

Arguments

.data

A tibble of class tabxplor_tab.

...

Columns to move. will move columns to the left-hand side; specifying both is an error.

Value

An object of class tabxplor_grouped_tab.


rename_with method for class tabxplor_grouped_tab

Description

rename_with method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
rename_with(.data, .fn, .cols = dplyr::everything(), ...)

Arguments

.data

A tibble of class tabxplor_tab.

.fn

A function used to transform the selected .cols. Should return a character vector the same length as the input.

.cols

Columns to rename; defaults to all columns.

...

Additional arguments passed onto .fn.

Value

An object of class tabxplor_grouped_tab.


rename method for class tabxplor_grouped_tab

Description

rename method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
rename(.data, ...)

Arguments

.data

A tibble of class tabxplor_tab.

...

Use new_name = old_name to rename selected variables.

Value

An object of class tabxplor_grouped_tab.


rowwise method for class tabxplor_grouped_tab

Description

rowwise method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
rowwise(data, ...)

Arguments

data

A tibble of class tabxplor_tab.

...

Variables to be preserved when calling summarise(). This is typically a set of variables whose combination uniquely identify each row.

Value

An object of class tabxplor_grouped_tab and rowwise_df.


rowwise method for class tabxplor_tab

Description

rowwise method for class tabxplor_tab

Usage

## S3 method for class 'tabxplor_tab'
rowwise(data, ...)

Arguments

data

A tibble of class tabxplor_tab.

...

Variables to be preserved when calling summarise(). This is typically a set of variables whose combination uniquely identify each row.

Value

A tibble of class tabxplor_grouped_tab and rowwise_df.


Create a score variable from factors

Description

Create a score variable from factors

Usage

score_from_lv1(data, name, vars_list)

Arguments

data

A data.frame.

name

The name of the variable to create.

vars_list

The list of the factors to count (only the first level is counted, as 1) ; as a character vector.

Value

The data.frame, with a new variable.

Examples

data <- tibble::tibble(group = factor(c("G1", "G1", "G2", "G2", "G3", "G3")),
                       a = factor(c("Oui", "Oui", "Oui", "Oui", "Non", "Oui")),
                       b = factor(c("Oui", "Non", "Non", "Oui", "Non", "Oui")),
                       c = factor(c("Oui", "Oui", "Non", "Non", "Oui", "Oui")))
data |>
  score_from_lv1("score", vars_list = c("a", "b", "c")) |>
  tab(group, score, digits = 1)

select method for class tabxplor_grouped_tab

Description

select method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
select(.data, ...)

Arguments

.data

A tibble of class tabxplor_tab.

...

One or more unquoted expressions separated by commas. Variable names can be used as if they were positions in the data frame, so expressions like x:y can be used to select a range of variables.

Value

An object of class tabxplor_grouped_tab.


Set the "display" vctrs::field of a fmt vector.

Description

Set the "display" vctrs::field of a fmt vector.

Usage

## S3 method for class 'data.frame'
set_display(x, value)

Arguments

x

The object to test, to get a field in, or to modify.

value

The value you want to inject in some fmt vector's vctrs::field or attribute using a given "set" function.

Value

The entered objects, with all fmt vectors with the wanted display.


Set the "display" vctrs::field of a fmt vector.

Description

Set the "display" vctrs::field of a fmt vector.

Usage

## Default S3 method:
set_display(x, value)

Arguments

x

The object to test, to get a field in, or to modify.

value

The value you want to inject in some fmt vector's vctrs::field or attribute using a given "set" function.

Value

The entered vector (nothing happens).


Set the "display" vctrs::field of a fmt vector.

Description

Set the "display" vctrs::field of a fmt vector.

Usage

## S3 method for class 'tabxplor_fmt'
set_display(x, value)

Arguments

x

The object to test, to get a field in, or to modify.

value

The value you want to inject in some fmt vector's vctrs::field or attribute using a given "set" function.

Value

A fmt vectors with the wanted display.


summarise method for class tabxplor_grouped_tab

Description

summarise method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
summarise(.data, ..., .groups = NULL)

Arguments

.data

A tibble of class tabxplor_tab.

...

Name-value pairs of summary functions. The name will be the name of the variable in the result.

.groups

Grouping structure of the result.

Value

An object of class tabxplor_grouped_tab.


Single cross-table, with color helpers

Description

A full-featured function to create, manipulate and format single cross-tables, using colors to make the printed tab more easily readable (in R terminal or exported to Excel with tab_xl). Since objects of class tabxplor_tab are also of class tibble, you can then use all dplyr verbs to modify the result, like select, like arrange, filter or mutate. Wrapper around the more powerful tab_many.

Usage

tab(
  data,
  row_var,
  col_var,
  tab_vars,
  wt,
  sup_cols,
  pct = "no",
  color = "no",
  OR = "no",
  chi2 = FALSE,
  na = "keep",
  cleannames = NULL,
  other_if_less_than = 0,
  other_level = "Others",
  ref = "auto",
  ref2 = "first",
  comp = "tab",
  ci = "no",
  conf_level = 0.95,
  totaltab = "line",
  totaltab_name = "Ensemble",
  tot = c("row", "col"),
  total_names = "Total",
  add_n = TRUE,
  add_pct = FALSE,
  subtext = "",
  digits = 0,
  filter
)

Arguments

data

A data frame.

row_var, col_var

The row variable, which will be printed with one level per line, and the column variable, which will be printed with one level per column. For numeric variables means are calculated, in a single column.

tab_vars

<tidy-select> Tab variables : a subtable is made for each combination of levels of the selected variables. Leave empty to make a simple cross-table. All tab_vars are converted to factor.

wt

A weight variable, of class numeric. Leave empty for unweighted results.

sup_cols

<tidy-select> Supplementary columns variables, with only the first level printed, and row percentages (for numeric variables, a mean will be calculated for each row_var). To pass many variables you may use syntax sup_cols = c(sup_col1, sup_col2, ...). To keep all levels of other col_vars, or other types of percentages, use tab_many instead.

pct

The type of percentages to calculate :

  • "row": row percentages.

  • "col": column percentages.

  • "all": frequencies for each subtable/group, if there is tab_vars.

  • "all_tabs": frequencies for the whole (set of) table(s).

color

The type of colors to print, as a single string :

  • "no": by default, no colors are printed.

  • "diff": color percentages and means based on cells differences from totals (or from first cells when ref = "first").

  • "diff_ci": color pct and means based on cells differences from totals or first cells, removing coloring when the confidence interval of this difference is higher than the difference itself.

  • "after_ci": idem, but cut off the confidence interval from the difference first.

  • "contrib": color cells based on their contribution to variance (except mean columns, from numeric variables).

  • "OR": for pct == "col" or pct == "row", color based on odds ratios (or relative risks ratios)

  • "auto": frequencies (pct = "all", pct = "all_tabs") and counts are colored with "contrib". When ci = "diff", row and col percentages are colored with "after_ci" ; otherwise they are colored with "diff".

OR

With pct = "row" or pct = "col", calculate and print odds ratios (for binary variables) or relative risks ratios (for variables with 3 levels or more).

  • "no": by default, no OR are calculated.

  • "OR": print OR (instead of percentages).

  • "OR_pct": print OR, with percentages in bracket.

chi2

Set to TRUE to calculate Chi2 summaries with tab_chi2. Useful to print metadata, and to color cells based on their contribution to variance (color = "contrib"). Automatically added if needed for color.

na

The policy to adopt for missing values, as a single string :

  • "keep": by default, NA's of row, col and tab variables are printed as an explicit "NA" level.

  • "drop": remove NA's in row, col and tab variables before calculations are done. Supplementary columns are then calculated for observations with no NA in any of the row, col and tab variables.

cleannames

Set to TRUE to clean levels names, by removing prefix numbers like "1-", and text in parenthesis. All data formatting arguments are passed to tab_prepare.

other_if_less_than

When set to a positive integer, levels with less count than it will be merged into an "Others" level.

other_level

The name of the "Other" level, as a single string.

ref

The reference cell to calculate differences and ratios (used to print colors) :

  • "auto": by default, cell difference from the corresponding total (rows or cols depending on pct = "row" or pct = "col") is used for diff ; cell ratio from the first line (or col) is use for OR (odds ratio/relative risks ratio).

  • "tot": totals are always used.

  • "first": calculate cell difference or ratio from the first cell of the row or column (useful to color temporal developments).

  • n: when ref is an integer, the nth row (or column) is used for comparison.

  • "regex": when ref is a string, it it used as a regular expression, to match with the names of the rows (or columns). Be precise enough to match only one column or row, otherwise you get a warning message.

  • "no": not use ref and not calculate diffs to gain calculation time.

ref2

A second reference cell is needed to calculate odds ratios (or relative risks ratios). The first cell of the row or column is used by default. See ref above for the full list of possible values.

comp

The comparison level : by subtables/groups, or for the whole table.

  • "tab": by default, contributions to variance, row differences from totals/first cells, and row confidence intervals for these differences, are calculated for each tab_vars group.

  • "all": compare cells to the general total line (provided there is a total table with a total row), or with the first line of the total table when ref = "first".

ci

The type of confidence intervals to calculate, passed to tab_ci (automatically added if needed for color).

  • "cell": absolute confidence intervals of cells percentages.

  • "diff": confidence intervals of the difference between a cell and the relative total cell (or relative first cell when ref = "first").

  • "auto": ci = "diff" for means and row/col percentages, ci = "cell" for frequencies ("all", "all_tabs").

By default, for percentages, with Wilson's method is used, and with ci = "diff" Wald's method along Agresti and Caffo's adjustment. Means use classic method. This can be changed in tab_many. By default, with ci = "cell", the result is printed in the ⁠[inf;sup]⁠ form. Set options("tabxplor.ci_print" = "moe") to print pct +- moe instead.

conf_level

The confidence level, as a single numeric between 0 and 1. Default to 0.95 (95%).

totaltab

The total table, if there are subtables/groups (i.e. when tab_vars is provided) :

  • "line": by default, add a general total line (necessary for calculations with comp = "all")

  • "table": add a complete total table (i.e. row_var by col_vars without tab_vars).

  • "no": not to draw any total table.

totaltab_name

The name of the total table, as a single string.

tot

The totals :

  • c("col", "row") or "both" : by default, both total rows and total columns.

  • "row": only total rows.

  • "col": only total column.

  • "no": remove all totals (after calculations if needed).

total_names

The names of the totals, as a character vector of length one or two. Use syntax of type c("Total row", "Total column") to set different names for rows and cols.

add_n

For pct = "row" or pct = "col", set to FALSE not to add another column or row with unweighted counts (n).

add_pct

Set to TRUE to add a column with the frequencies of the row variable (for pct = "row") or a row with the frequencies of the column variable (for pct = "col").

subtext

A character vector to print rows of legend under the table.

digits

The number of digits to print, as a single integer. To print a different number of digits for each sup_cols, an integer vector of length 1 + sup_cols (the first being the number of digits for the base table).

filter

A dplyr::filter to apply to the data frame first, as a single string (which will be converted to code, i.e. to a call). Useful when printing multiples tabs with tibble::tribble, to use different filters for similar tables or simply make the field of observation more visible into the code.

Value

A tibble of class tab, possibly with colored reading helpers. All non-text columns are of class fmt, storing all the data necessary to print formats and colors. Columns with row_var and tab_vars are of class factor : every added factor will be considered as a tab_vars and used for grouping. To add text columns without using them in calculations, be sure they are of class character.

Examples

# A simple cross-table:
tab(forcats::gss_cat, marital, race)


# With more variables provided, `tab` makes a subtables for each combination of levels:

tab(forcats::gss_cat, marital, tab_vars = c(year, race))


# You can also add supplementary columns, text or numeric:

tab(dplyr::storms, category, status, sup_cols = c("pressure", "wind"))


# Colors to help the user read the table:
data <- forcats::gss_cat %>%
  dplyr::filter(year %in% c(2000, 2006, 2012), !marital %in% c("No answer", "Widowed"))
gss  <- "Source: General social survey 2000-2014"
gss2 <- "Source: General social survey 2000, 2006 and 2012"

# Differences between the cell and it's subtable's total cell:

tab(data, race, marital, year, subtext = gss2, pct = "row", color = "diff")


# Differences between the cell and the whole table's general total cell:

tab(data, race, marital, year, subtext = gss2, pct = "row", color = "diff",
  comp = "all")


# Historical differences:

data2 <- data %>% dplyr::mutate(year = as.factor(year))
tab(data2, year, marital, race, subtext = gss2, pct = "row",
    color = "diff", ref = "first", tot = "col")


# Differences with the total, except if their confidences intervals are superior to them:
tab(forcats::gss_cat, race, marital, subtext = gss, pct = "row", color = "diff_ci")

# Same differences, minus their confidence intervals:
tab(forcats::gss_cat, race, marital, subtext = gss, pct = "row", color = "after_ci")

# Contribution of cells to table's variance, like in a correspondence analysis:
tab(forcats::gss_cat, race, marital, subtext = gss, color = "contrib")


# Since the result is a tibble, you can use all dplyr verbs to modify it :

library(dplyr)
tab(dplyr::storms, category, status, sup_cols = c("pressure", "wind")) %>%
  dplyr::filter(category != "-1") %>%
  dplyr::select(-`tropical depression`) %>%
  dplyr::arrange(is_totrow(.), desc(category))



# With `dplyr::arrange`, don't forget to keep the order of tab variables and total rows:
tab(data, race, marital, year, pct = "row") %>%
  dplyr::arrange(year, is_totrow(.), desc(Married))

Add Chi2 summaries to a tab

Description

Add Chi2 summaries to a tab

Usage

tab_chi2(
  tabs,
  calc = c("ctr", "p", "var", "counts"),
  comp = NULL,
  color = c("no", "auto", "all", "all_pct")
)

Arguments

tabs

A tibble of class tab, made with tab_plain or tab_many.

calc

By default all elements of the Chi2 summary are calculated : contributions to variance, pvalue, variance and unweighted count. You can choose which are computed by selecting elements in the vector c("ctr", "p", "var", "counts").

comp

Comparison level. When tab_vars are present, should the contributions to variance be calculated for each subtable/group (by default, comp = "tab") ? Should they be calculated for the whole table (comp = "all") ? comp must be set once and for all the first time you use tab_plain, tab_num or tab_chi2 with rows, or tab_ci.

color

The type of colors to print, as a single string.

  • "no": by default, no colors are printed

  • "all": color all cells based on their contribution to variance (except for mean columns, from numeric variables)

  • "all_pct": color all percentages cells based on their contribution to variance

  • "auto": only color columns with counts, pct = "all" or pct = "all_tabs"

Value

A tibble of class tab, with Chi2 summaries as metadata, possibly colored based on contributions of cells to variance.


Add confidence intervals to a tab

Description

Add confidence intervals to a tab

Usage

tab_ci(
  tabs,
  ci = "auto",
  comp = NULL,
  conf_level = 0.95,
  color = "no",
  visible = FALSE,
  method_cell = "wilson",
  method_diff = "ac"
)

Arguments

tabs

A tibble of class tab made with tab_plain or tab_many.

ci

The type of ci to calculate. Set to "cell" to calculate absolute confidence intervals. Set to "diff" to calculate the confidence intervals of the difference between a cell and the relative total cell (or the reference cell, when ref is not "tot" in tab_plain or tab_num). By default, "diff" ci are calculated for means and row and col percentages, "cell" ci for frequencies ("all", "all_tabs"). By default, with ci = "cell", the result is printed in the ⁠[inf;sup]⁠ form. Set options("tabxplor.ci_print" = "moe") to print pct +- moe instead.

comp

Comparison level. When tab_vars are present, should the contributions to variance be calculated for each subtable/group (by default, comp = "tab") ? Should they be calculated for the whole table (comp = "all") ? comp must be set once and for all the first time you use tab_plain, tab_num or tab_chi2 with rows, or tab_ci.

conf_level

The confidence level, as a single numeric between 0 and 1. Default to 0.95 (95%).

color

The type of colors to print, as a single string.

  • "no": by default, no colors are printed

  • "diff_ci": color pct and means based on cells differences from totals or first cells, removing coloring when the confidence interval of this difference is higher than the difference itself

  • "after_ci": idem, but cut off the confidence interval from the difference

visible

By default confidence intervals are calculated and used to set colors, but not printed. Set to TRUE to print them in the result.

method_cell

Character string specifying which method to use with percentages for ci = "cell". This can be one out of: "wald", "wilson", "wilsoncc", "agresti-coull", "jeffreys", "modified wilson", "modified jeffreys", "clopper-pearson", "arcsine", "logit", "witting", "pratt", "midp", "lik" and "blaker". Defaults to "wilson". See BinomCI.

method_diff

Character string specifying which method to use with percentages for ci = "diff". This can be one out of: "wald", "waldcc", "ac", "score", "scorecc", "mn", "mee", "blj", "ha", "hal", "jp". Defaults to "ac", Wald interval with the adjustment according to Agresti, Caffo for difference in proportions and independent samples. See BinomDiffCI.

Value

A tibble of class tab, colored based on differences (from totals/first cells) and confidence intervals.

Examples

# A typical workflow with tabxplor step-by-step functions :

data <- dplyr::starwars %>%
  tab_prepare(sex, hair_color, gender, other_if_less_than = 5,
              na_drop_all = sex)

data %>%
  tab_plain(sex, hair_color, gender, tot = c("row", "col"),
    pct = "row", comp = "all") %>%
    tab_ci("diff", color = "after_ci")

Bind a list of tabs with the same col_vars (and no tab_vars) into a single tab

Description

Bind a list of tabs with the same col_vars (and no tab_vars) into a single tab

Usage

tab_compact(tabs)

Arguments

tabs

A list of tabxplor_tab (or a tabxplor_tab)

Value

A tabxplor_tab

Examples

forcats::gss_cat |>
  tab_many(c(race, rincome), marital, pct = "row", color = "diff") |>
  tab_compact()

Get the number of actual rows and the max character length of a table after being wrapped (count ⁠\n⁠ as a linebreak).

Description

Get the number of actual rows and the max character length of a table after being wrapped (count ⁠\n⁠ as a linebreak).

Usage

tab_get_wrapped_dimensions(tabs, no_tab_vars = FALSE, width_pad = 4L)

Arguments

tabs

A data.frame.

no_tab_vars

For data.frame of class tabxplor_tab, remove tab_vars.

width_pad

Number of characters lengths between columns.


Print a tabxplor table in html

Description

Print a tabxplor table in html

Usage

tab_kable(
  tabs,
  theme = c("light", "dark"),
  color_type = NULL,
  html_24_bit = NULL,
  tooltips = TRUE,
  popover = NULL,
  color_legend = TRUE,
  caption = knitr::opts_current$get("tab.cap"),
  html_font = NULL,
  get_data = FALSE,
  full_width = FALSE,
  wrap_rows = 35,
  wrap_cols = 15,
  whitespace_only = TRUE,
  ...
)

Arguments

tabs

A table made with tab or tab_many, or a list of tab with the same col_vars and no tab_vars.

theme

By default, a white table with black text, Set to "dark" for a black table with white text.

color_type

Set to "text" to color the text, "bg" to color the background. By default it takes getOption("tabxplor.color_style_type").

html_24_bit

Use 24bits colors palettes for html tables : set to "green_red" or "blue_red". Only with mode = "color_code" (not mode = "crayon") and ⁠theme = "light⁠. Default to getOption("tabxplor.color_html_24_bit").

tooltips

By default, html tooltips are used to display additional informations at mouse hover. Set to FALSE to discard.

popover

By default, takes getOption("tabxplor.kable_popover"). When FALSE, html tooltips are of the base kind : they can't be used with floating table of content in rmarkdown documents. Set to TRUE to use kableExtra html popovers instead, which are compatible with floating toc. Remember to enable the popover module by copying the following code into your document : <script> $(document).ready(function(){ $('[data-toggle="popover"]').popover(); }); </script>

color_legend

Print colors legend below the table ? You can then use a css chunk in rmarkdown to change popovers colors.

caption

The table caption. For formatting, you need to use a css with ⁠caption{}⁠in rmarkdown.

html_font

A string for HTML css font. By default, it uses '"DejaVu Sans", "Arial", arial, helvetica, sans-serif'. Set another default by setting options("tabxplor.kable_html_font" = ).

get_data

Get the transformed data instead of the html table.

full_width

A TRUE or FALSE variable controlling whether the HTML table should have the preferable format for full_width. If not specified, a HTML table will have full width by default but this option will be set to FALSE for a LaTeX table.

wrap_rows

By default, rownames are wrapped when larger than 30 characters.

wrap_cols

By default, colnames are wrapped when larger than 12 characters.

whitespace_only

Set to FALSE to wrap also on non whitespace characters.

...

Other arguments to pass to kableExtra::kable_styling.

Value

A html table (opened in the viewer in RStudio). Differences from totals, confidence intervals, contribution to variance, and unweighted counts, are available in an html tooltip at cells hover.

Examples

tabs <- tab(forcats::gss_cat, race, marital, year, pct = "row", color = "diff")
tab_kable(tabs, theme = "light", color_type = "text")

Many cross-tables as one, with color helpers

Description

A full-featured function to create, manipulate and format many cross-tables as one, using colors to make the printed tab more easily readable (in R terminal or exported to Excel with tab_xl). Since objects of class tabxplor_tab are also of class tibble, you can then use all dplyr verbs to modify the result, like select, arrange, filter or mutate.

Only breaks for attractions/over-representations (in green) should be given, as a vector of positive doubles, with length between 1 and 5. Breaks for aversions/under-representations (in orange/red) will simply be the opposite.

Usage

tab_many(
  data,
  row_vars,
  col_vars,
  tab_vars,
  wt,
  pct = "no",
  color = "no",
  OR = "no",
  chi2 = FALSE,
  na = "keep",
  levels = "all",
  na_drop_all,
  cleannames = NULL,
  compact = NULL,
  other_if_less_than = 0,
  other_level = "Others",
  ref = "auto",
  ref2 = "first",
  comp = "tab",
  ci = "no",
  conf_level = 0.95,
  method_cell = "wilson",
  method_diff = "ac",
  totaltab = "line",
  totaltab_name = "Ensemble",
  totrow = TRUE,
  totcol = "last",
  total_names = "Total",
  add_n = TRUE,
  add_pct = FALSE,
  digits = 0,
  subtext = "",
  filter
)

tab_get_vars(tabs, vars = c("row_var", "col_vars", "tab_vars"))

is_tab(x)

set_color_style(
  type = c("text", "bg"),
  theme = NULL,
  html_24_bit = c("blue_red", "green_red", "no"),
  custom_palette = NULL
)

get_color_style(
  mode = c("crayon", "color_code"),
  type = NULL,
  theme = NULL,
  html_24_bit = NULL
)

set_color_breaks(pct_breaks, mean_breaks, contrib_breaks)

get_color_breaks(brk, type = c("positive", "all"))

Arguments

data

A data frame.

row_vars

The row variable, which will be printed with one level per line. If numeric, it will be converted to factor. If more than one row_var if provided, a different table is made for each of them.

col_vars

<tidy-select> One column is printed for each level of each column variable. For numeric variables means are calculated, in a single column. To pass many variables you may use syntax col_vars = c(col_var1, col_var2, ...).

tab_vars

<tidy-select> One subtable is made for each combination of levels of the tab variables. To pass many variables you may use syntax tab_vars = c(tab_var1, tab_var2, ...). All tab variables are converted to factor. Leave empty to make a simple table.

wt

A weight variable, of class numeric. Leave empty for unweighted results.

pct

The type of percentages to calculate :

  • "row": row percentages.

  • "col": column percentages.

  • "all": frequencies for each subtable/group, if there is tab_vars.

  • "all_tabs": frequencies for the whole (set of) table(s).

The argument is vectorised over both row_vars and col_vars. You can then write as the following : pct = list(row_var1 = list("row", "col", "col"), row_var2 = list("col", "row", "row"))

color

The type of colors to print, as a single string. Vectorised over row_vars.

  • "no": by default, no colors are printed.

  • "diff": color percentages and means based on cells differences from totals (or from first cells when ref = "first").

  • "diff_ci": color pct and means based on cells differences from totals or first cells, removing coloring when the confidence interval of this difference is higher than the difference itself.

  • "after_ci": idem, but cut off the confidence interval from the difference first.

  • "contrib": color cells based on their contribution to variance (except mean columns, from numeric variables).

  • "OR": for pct == "col" or pct == "row", color based on odds ratios (or relative risks ratios)

  • "auto": frequencies (pct = "all", pct = "all_tabs") and counts are colored with "contrib". When ci = "diff", row and col percentages are colored with "after_ci" ; otherwise they are colored with "diff".

OR

With pct = "row" or pct = "col", calculate and print odds ratios (for binary variables) or relative risks ratios (for variables with 3 levels or more).

  • "no": by default, no OR are calculated.

  • "OR": print OR (instead of percentages).

  • "OR_pct": print OR, with percentages in bracket.

chi2

Set to TRUE to calculate Chi2 summaries with tab_chi2. Useful to print metadata, and to color cells based on their contribution to variance (color = "contrib"). Vectorised over row_vars.

na

The policy to adopt with missing values. It must be a single string.

  • na = "keep": by default, prints NA's as explicit "NA" level.

  • na = "drop": removes NA levels before making each table (tabs made with different column variables may have a different number of observations, and won't exactly have the same total columns).

  • "drop_all": remove NA's for all variables before making the tables.

levels

The levels of col_vars to keep (for more complex selections use dplyr::select). The argument is vectorised over col_vars.

  • "all": by default, all levels are kept.

  • "first": only keep the first level of each col_vars

  • "auto": keep the first level when col_var is only two levels, keep all levels otherwise

na_drop_all

<tidy-select> Removes all observations with a NA in any of the chosen variables, for all tables (tabs for each column variable will have the same number of observations).

cleannames

Set to TRUE to clean levels names, by removing prefix numbers like "1-", and text in parenthesis. All data formatting arguments are passed to tab_prepare.

compact

With several row_vars, set to TRUE to bind all tables in a single tabxplor_tab.

other_if_less_than

When set to a positive integer, levels with less count than it will be merged into an "Others" level.

other_level

The name of the "Other" level, as a single string.

ref

The reference cell to calculate differences and ratios (used to print colors) :

  • "auto": by default, cell difference from the corresponding total (rows or cols depending on pct = "row" or pct = "col") is used for diff ; cell ratio from the first line (or col) is use for OR (odds ratio/relative risks ratio).

  • "tot": totals are always used.

  • "first": calculate cell difference or ratio from the first cell of the row or column (useful to color temporal developments).

  • n: when ref is an integer, the nth row (or column) is used for comparison.

  • "regex": when ref is a string, it it used as a regular expression, to match with the names of the rows (or columns). Be precise enough to match only one column or row, otherwise you get a warning message.

  • "no": not use ref and not calculate diffs to gain calculation time.

ref2

A second reference cell is needed to calculate odds ratios (or relative risks ratios). The first cell of the row or column is used by default. See ref above for the full list of possible values.

comp

The comparison level : by subtables/groups, or for the whole table. Vectorised over row_vars.

  • "tab": by default, contributions to variance, row differences from totals/first cells, and row confidence intervals for these differences, are calculated for each tab_vars group.

  • "all": compare cells to the general total line (provided there is a total table with a total row), or with the reference line of the total table when ref = "first", an integer or a regular expression.

ci

The type of confidence intervals to calculate, passed to tab_ci. Vectorised over row_vars.

  • "cell": absolute confidence intervals of cells percentages.

  • "diff": confidence intervals of the difference between a cell and the relative total cell (or relative first cell when ref = "first").

  • "auto": ci = "diff" for means and row/col percentages, ci = "cell" for frequencies ("all", "all_tabs").

By default, for percentages, with ci = "cell" Wilson's method is used, and with ci = "diff" Wald's method along Agresti and Caffo's adjustment. Means use classic method. This can be changed with method_cell and method_diff. By default, with ci = "cell", the result is printed in the ⁠[inf;sup]⁠ form. Set options("tabxplor.ci_print" = "moe") to print pct +- moe instead.

conf_level

The confidence level, as a single numeric between 0 and 1. Default to 0.95 (95%).

method_cell

Character string specifying which method to use with percentages for ci = "cell". This can be one out of: "wald", "wilson", "wilsoncc", "agresti-coull", "jeffreys", "modified wilson", "modified jeffreys", "clopper-pearson", "arcsine", "logit", "witting", "pratt", "midp", "lik" and "blaker". Defaults to "wilson". See BinomCI.

method_diff

Character string specifying which method to use with percentages for ci = "diff". This can be one out of: "wald", "waldcc", "ac", "score", "scorecc", "mn", "mee", "blj", "ha", "hal", "jp". Defaults to "ac", Wald interval with the adjustment according to Agresti, Caffo for difference in proportions and independent samples. See BinomDiffCI.

totaltab

The total table, if there are subtables/groups (i.e. when tab_vars is provided). Vectorised over row_vars.

  • "line": by default, add a general total line (necessary for calculations with comp = "all")

  • "table": add a complete total table (i.e. row_var by col_vars without tab_vars).

  • "no": not to draw any total table.

totaltab_name

The name of the total table, as a single string.

totrow

By default, total rows are printed. Set to FALSE to remove them (after calculations if needed). Vectorised over row_vars.

totcol

The policy with total columns. Vectorised over col_vars.

  • "last": by default, only prints a total column for the last column variable (of class factor, not numeric).

  • "each": print a total column for each column variable.

  • "no": remove all total columns (after calculations if needed).

total_names

The names of the totals, as a character vector of length one or two. Use syntax of type c("Total row", "Total column") to set different names for rows and cols.

add_n

For pct = "row" or pct = "col", set to FALSE not to add another column or row with unweighted counts (n).

add_pct

Set to TRUE to add a column with the frequencies of the row variable (for pct = "row") or a row with the frequencies of the column variable (for pct = "col").

digits

The number of digits to print, as a single integer, or an integer vector the same length as col_vars. The argument is vectorisez over col_vars.

subtext

A character vector to print rows of legend under the table.

filter

A dplyr::filter to apply to the data frame first, as a single string (which will be converted to code, i.e. to a call). Useful when printing multiples tabs with tibble::tribble, to use different filters for similar tables or simply make the field of observation more visible into the code.

tabs

A tibble of class tab, made with tab, tab_many or tab_plain.

vars

In tab_get_vars, a character vector containing the wanted vars names: "row_var", "col_vars" or "tab_vars".

x

A object to test with is_tab.

type

Default to "positive", which just print breaks for positive spreads. Set to all to get breaks for negative spreads as well.

theme

For set_color_style and get_color_style, is your console or html table background "light" or "dark" ? Default to RStudio theme.

html_24_bit

Use 24bits colors palettes for html tables : set to "green_red" or "blue_red". Only with mode = "color_code" (not mode = "crayon") and ⁠theme = "light⁠. Default to getOption("tabxplor.color_html_24_bit").

custom_palette

Possibility to provide a custom color styles, as a character vector of 10 html color codes (the five first for over-represented numbers, the five last for under-represented ones). The result is saved to options("tabxplor.color_style"). To discard, relaunch the function with custom_palette = NULL.

mode

By default, get_color_style returns a list of crayon coloring functions. Set to "color_code" to return html color codes.

pct_breaks

If they are to be changed, the breaks used for percentages. Default to c(0.05, 0.1, 0.2, 2, 0.3) : first color used when the pct of a cell is +5% superior to the pct of the related total ; second color used when it is +10% superior ; third +20% superior ; fourth *2 superior ; fifth +30% superior. When > 1, it does not take differences but ratio. The opposite for cells inferior to the total (without the *2 rule). With color = "after_ci", the first break is subtracted from all breaks (default becomes c(0, 0.05, 0.15, 2, 0.25) : +0%, +5%, +15%, *2, +25%).

mean_breaks

If they are to be changed, the breaks used for means. Default to c(1.15, 1.5, 2, 4) : first color used when the mean of a cell is superior to 1.15 times the mean of the related total row ; second color used when it is superior to 1.5 times ; etc. The opposite for cells inferior to the total. With color = "after_ci", the first break is divided from all breaks (default becomes c(1, 1.3, 1.7, 3.5)).

contrib_breaks

If they are to be changed, the breaks used for contributions to variance. Default to c(1, 2, 5, 10) : first color used when the contribution of a cell is superior to the mean contribution ; second color used when it is superior to 2 times the mean contribution ; etc. The global color (for example green or red/orange) is given by the sign of the spread.

brk

When missing, return all color breaks. Specify to return a given color break, among "pct", "mean", "contrib", "pct_ci" and "mean_ci".

Value

A tibble of class tab, possibly with colored reading helpers. When there are two row_vars or more, a list of tibble of class tab. All non-text columns are of class fmt, storing all the data necessary to print formats and colors. Columns with row_var and tab_vars are of class factor : every added factor will be considered as a tab_vars and used for grouping. To add text columns without using them in calculations, be sure they are of class character.

A list with the variables names.

A single logical.

Set global options "tabxplor.color_style_type" and "tabxplor.color_style_theme", used when printing tab objects.

A vector of crayon color functions, or a vector of color html codes.

Set the global option "tabxplor.color_breaks" as a list different double vectors, and also returns it invisibly.

The color breaks as a double vector, or list of double vectors.

Functions

  • tab_get_vars(): Get the variables names of a tabxplor tab

  • is_tab(): a test function for class tabxplor_tab

  • set_color_style(): define the color style used to print tab.

  • get_color_style(): get color styles as crayon functions or html codes.

  • set_color_breaks(): set the breaks used to print colors

  • get_color_breaks(): get the breaks currently used to print colors

Examples

# Make a summary table with many col_vars, showing only one specific level :

library(dplyr)
first_lvs <- c("Married", "$25000 or more", "Strong republican", "Protestant")
data <- forcats::gss_cat %>% mutate(across(
  where(is.factor),
  ~ forcats::fct_relevel(., first_lvs[first_lvs %in% levels(.)])
))
tab_many(data, race, c(marital, rincome, partyid, relig, age, tvhours),
         levels = "first", pct = "row", chi2 = TRUE, color = "auto")


# Can be used with map and tribble to program several tables with different parameters
#  all at once, in a readable way:

library(purrr)
library(tibble)
pmap(
  tribble(
    ~row_var, ~col_vars       , ~pct , ~filter              , ~subtext               ,
    "race"  , "marital"       , "row", NULL                 , "Source: GSS 2000-2014",
    "relig" , c("race", "age"), "row", "year %in% 2000:2010", "Source: GSS 2000-2010",
    NA_character_, "race"     , "no" , NULL                 , "Source: GSS 2000-2014",
  ),
  .f = tab_many,
  data = forcats::gss_cat, color = "auto", chi2 = TRUE)

set_color_style(type = "bg")
set_color_breaks(
  pct_breaks = c(0.05, 0.15, 0.3),
  mean_breaks = c(1.15, 2, 4),
  contrib_breaks = c(1, 2, 5)
)

Means table

Description

Cross categorical variables with numeric variables, and get a table of means and standard deviations.

Usage

tab_num(
  data,
  row_var,
  col_vars,
  tab_vars,
  wt,
  color = c("auto", "diff", "diff_ci", "after_ci"),
  na = c("keep", "drop", "drop_fct", "drop_num"),
  ref = "tot",
  comp = c("tab", "all"),
  ci = NULL,
  conf_level = 0.95,
  totaltab = "line",
  totaltab_name = "Ensemble",
  tot = NULL,
  total_names = "Total",
  subtext = "",
  digits = 0,
  num = FALSE,
  df = FALSE
)

Arguments

data

A data frame.

row_var

The row variable, which will be printed with one level per line. If numeric, it will be used as a factor.

col_vars

The numeric variables, which will appear in columns : means and standard deviation are calculated for each levels of row_var and tab_vars.

tab_vars

<tidy-select> Tab variables : a subtable is made for each combination of levels of the selected variables. Leave empty to make a simple cross-table. All tab variables are converted to factor.

wt

A weight variable, of class numeric. Leave empty for unweighted results.

color

TRUE print the color percentages and means based on cells differences from totals or reference cell, as provided by ref. Default to FALSE, no colors.

na

The policy to adopt for missing values in row and tab variables (factors), as a single string.

  • "keep": by default, NA's of row and tab variables are printed as an explicit "NA" level.

  • "drop": remove NA's in row and tab variables.

NAs in numeric variables are always removed when calculating means. For that reason the n field of each resulting fmt column, used to calculate confidence intervals, only takes into account the complete observations (without NA). To drop all rows with NA in any numeric variable first, use tab_prepare or tab_many with the na_drop_all argument.

ref

The reference cell to calculate differences and ratios (used to print colors) :

  • "auto": by default, cell difference from the corresponding total (rows or cols depending on pct = "row" or pct = "col") is used for diff ; cell ratio from the first line (or col) is use for OR (odds ratio/relative risks ratio).

  • "tot": totals are always used.

  • "first": calculate cell difference or ratio from the first cell of the row or column (useful to color temporal developments).

  • n: when ref is an integer, the nth row (or column) is used for comparison.

  • "regex": when ref is a string, it it used as a regular expression, to match with the names of the rows (or columns). Be precise enough to match only one column or row, otherwise you get a warning message.

  • "no": not use ref and not calculate diffs to gain calculation time.

comp

Comparison level. When tab_vars are present, should the contributions to variance be calculated for each subtable/group (by default, comp = "tab") ? Should they be calculated for the whole table (comp = "all") ? comp must be set once and for all the first time you use tab_plain, tab_num or tab_chi2 with rows, or tab_ci.

ci

The type of confidence intervals to calculate, passed to tab_ci (automatically added if needed for color).

  • "cell": absolute confidence intervals of cells percentages.

  • "diff": confidence intervals of the difference between a cell and the relative total cell (or relative first cell when ref = "first").

  • "auto": ci = "diff" for means and row/col percentages, ci = "cell" for frequencies ("all", "all_tabs").

conf_level

The confidence level for the confidence intervals, as a single numeric between 0 and 1. Default to 0.95 (95%).

totaltab

The total table, if there are subtables/groups (i.e. when tab_vars is provided) :

  • "line": by default, add a general total line (necessary for calculations with comp = "all")

  • "table": add a complete total table (i.e. row_var by col_vars without tab_vars).

  • "no": not to draw any total table.

totaltab_name

The name of the total table, as a single string.

tot

The totals :

  • c("col", "row") or "both" : by default, both total rows and total columns.

  • "row": only total rows.

  • "col": only total column.

  • "no": remove all totals (after calculations if needed).

total_names

The names of the totals, as a character vector of length one or two. Use syntax of type c("Total row", "Total column") to set different names for rows and cols.

subtext

A character vector to print rows of legend under the table.

digits

The number of digits to print, as a single integer.

num

Set to TRUE to obtain a table with normal numeric vectors (not fmt).

df

Set to TRUE to obtain a plain data.frame (not a tibble), with normal numeric vectors (not fmt). Useful, for example, to pass the table to correspondence analysis with FactoMineR.

Value

A tibble of class tabxplor_tab. If ... (tab_vars) are provided, a tab of class tabxplor_grouped_tab. All non-text columns are fmt vectors of class tabxplor_fmt, storing all the data necessary to print formats and colors. Columns with row_var and tab_vars are of class factor : every added factor will be considered as a tab_vars and used for grouping. To add text columns without using them in calculations, be sure they are of class character.

Examples

data <- dplyr::storms %>% tab_prepare(category, wind, na_drop_all = wind)
tab_num(data, category, wind, tot = "row", color = "after_ci")

Add percentages and diffs to a tab

Description

Add percentages and diffs to a tab

Usage

tab_pct(
  tabs,
  pct = "row",
  digits = NULL,
  ref = c("tot", "first", "no"),
  comp = NULL,
  color = FALSE,
  just_diff = FALSE
)

Arguments

tabs

A tibble of class tab made with tab_plain or tab_many.

pct

The type of percentages to calculate. "row" draw row percentages. Set to "col" for column percentages. Set to "all" for frequencies (based on each subtable/group if tab_vars is provided). Set to "all_tabs" to calculate frequencies based on the whole (set of) table(s).

digits

The number of digits to print for percentages. As a single integer, or an integer vector the same length than col_vars.

ref

The reference cell to calculate differences and ratios (used to print colors) :

  • "auto": by default, cell difference from the corresponding total (rows or cols depending on pct = "row" or pct = "col") is used for diff ; cell ratio from the first line (or col) is use for OR (odds ratio/relative risks ratio).

  • "tot": totals are always used.

  • "first": calculate cell difference or ratio from the first cell of the row or column (useful to color temporal developments).

  • n: when ref is an integer, the nth row (or column) is used for comparison.

  • "regex": when ref is a string, it it used as a regular expression, to match with the names of the rows (or columns). Be precise enough to match only one column or row, otherwise you get a warning message.

  • "no": not use ref and not calculate diffs to gain calculation time.

comp

Comparison level. When tab_vars are present, should the row differences be calculated for each subtable/group (by default comp = "tab" : comparison of each cell to the relative total row) ? Should they be calculated for the whole table (comp = "all" : comparison of each cell to the total row of the total table) ? When comp = "all" and ref = "first", cells are compared to the first cell of the total table instead. This parameter doesn't affect column percentages. comp must be set once and for all the first time you use tab_chi2, tab_pct with rows, or tab_ci.

color

Set to TRUE to color the resulting tab based on differences (from totals or from the first cell).

just_diff

If percentages are already calculated and you just want to recalculate differences.

Value

A tibble of class tab, with percentages displayed, possibly colored based on differences from totals or first cell.


Plain single cross-table

Description

Plain single cross-table

Usage

tab_plain(
  data,
  row_var,
  col_var,
  tab_vars,
  wt,
  pct = "no",
  color = "no",
  OR = "no",
  na = "keep",
  ref = "auto",
  ref2 = "first",
  comp = "tab",
  totaltab = "line",
  totaltab_name = "Ensemble",
  tot = NULL,
  total_names = "Total",
  subtext = "",
  digits = 0,
  num = FALSE,
  df = FALSE
)

Arguments

data

A data frame.

row_var, col_var

The row variable, which will be printed with one level per line, and the column variable, which will be printed with one level per column. Numeric variables will be used as factors. To calculate means, use tab_num.

tab_vars

<tidy-select> Tab variables : a subtable is made for each combination of levels of the selected variables. Leave empty to make a simple cross-table. All tab variables are converted to factor.

wt

A weight variable, of class numeric. Leave empty for unweighted results.

pct

The type of percentages to calculate :

  • "row": row percentages.

  • "col": column percentages.

  • "all": frequencies for each subtable/group, if there is tab_vars.

  • "all_tabs": frequencies for the whole (set of) table(s).

color

The type of colors to print, as a single string :

  • "no": by default, no colors are printed.

  • "diff": color percentages and means based on cells differences from totals (or from first cells when ref = "first").

  • "OR": for pct == "col" or pct == "row", color based on odds ratios (or relative risks ratios)

OR

With pct = "row" or pct = "col", calculate and print odds ratios (for binary variables) or relative risks ratios (for variables with 3 levels or more).

  • "no": by default, no OR are calculated.

  • "OR": print OR (instead of percentages).

  • "OR_pct": print OR, with percentages in bracket.

na

The policy to adopt with missing values, as a single string.

  • "keep": by default, NA's of row, col and tab variables are printed as explicit "NA" level.

  • "drop": removes NA of row, col and tab variables.

ref

The reference cell to calculate differences and ratios (used to print colors) :

  • "auto": by default, cell difference from the corresponding total (rows or cols depending on pct = "row" or pct = "col") is used for diff ; cell ratio from the first line (or col) is use for OR (odds ratio/relative risks ratio).

  • "tot": totals are always used.

  • "first": calculate cell difference or ratio from the first cell of the row or column (useful to color temporal developments).

  • n: when ref is an integer, the nth row (or column) is used for comparison.

  • "regex": when ref is a string, it it used as a regular expression, to match with the names of the rows (or columns). Be precise enough to match only one column or row, otherwise you get a warning message.

  • "no": not use ref and not calculate diffs to gain calculation time.

ref2

A second reference cell is needed to calculate odds ratios (or relative risks ratios). The first cell of the row or column is used by default. See ref above for the full list of possible values.

comp

Comparison level. When tab_vars are present, should the contributions to variance be calculated for each subtable/group (by default, comp = "tab") ? Should they be calculated for the whole table (comp = "all") ? comp must be set once and for all the first time you use tab_plain, tab_num or tab_chi2 with rows, or tab_ci.

totaltab

The total table, if there are subtables/groups (i.e. when tab_vars is provided) :

  • "line": by default, add a general total line (necessary for calculations with comp = "all")

  • "table": add a complete total table (i.e. row_var by col_vars without tab_vars).

  • "no": not to draw any total table.

totaltab_name

The name of the total table, as a single string.

tot

The totals :

  • c("col", "row") or "both" : by default, both total rows and total columns.

  • "row": only total rows.

  • "col": only total column.

  • "no": remove all totals (after calculations if needed).

total_names

The names of the totals, as a character vector of length one or two. Use syntax of type c("Total row", "Total column") to set different names for rows and cols.

subtext

A character vector to print rows of legend under the table.

digits

The number of digits to print, as a single integer.

num

Set to TRUE to obtain a table with normal numeric vectors (not fmt).

df

Set to TRUE to obtain a plain data.frame (not a tibble), with normal numeric vectors (not fmt). Useful, for example, to pass the table to correspondence analysis with FactoMineR.

Value

A tibble of class tabxplor_tab. If ... (tab_vars) are provided, a tab of class tabxplor_grouped_tab. All non-text columns are fmt vectors of class tabxplor_fmt, storing all the data necessary to print formats and colors. Columns with row_var and tab_vars are of class factor : every added factor will be considered as a tab_vars and used for grouping. To add text columns without using them in calculations, be sure they are of class character.

Examples

# A typical workflow with tabxplor step-by-step functions :

data <- dplyr::starwars %>% tab_prepare(sex, hair_color)

data %>%
  tab_plain(sex, hair_color, tot = c("row", "col"), pct = "row") %>%
  tab_chi2() %>%
  tab_ci(color = "after_ci")

Print a tabxplor table as plot

Description

Print a tabxplor table as plot

Usage

tab_plot(
  tabs,
  theme = c("light", "dark"),
  color_type = NULL,
  html_24_bit = NULL,
  color_legend = TRUE,
  caption = NULL,
  wrap_rows = 35,
  wrap_cols = 14,
  whitespace_only = TRUE
)

Arguments

tabs

A table made with tab or tab_many.

theme

By default, a white table with black text, Set to "dark" for a black table with white text.

color_type

Set to "text" to color the text, "bg" to color the background. By default it takes getOption("tabxplor.color_style_type").

html_24_bit

Use 24bits colors palettes for html tables : set to "green_red" or "blue_red". Only with mode = "color_code" (not mode = "crayon") and ⁠theme = "light⁠. Default to getOption("tabxplor.color_html_24_bit").

color_legend

Print colors legend below the table ?

caption

The table caption.

wrap_rows

By default, rownames are wrapped when larger than 30 characters.

wrap_cols

By default, colnames are wrapped when larger than 12 characters.

whitespace_only

Set to FALSE to wrap also on non whitespace characters.

Value

A ggplot object to be printed in the RStudio Plots pane or exported as image, using ggtexttable.

Examples

tab(forcats::gss_cat, race, marital, pct = "row", color = "diff") |>
  tab_plot()

Prepare data for tab_plain.

Description

Prepare data for tab_plain.

Usage

tab_prepare(
  data,
  ...,
  na_drop_all,
  cleannames = NULL,
  other_if_less_than = 0,
  other_level = "Others"
)

Arguments

data

A dataframe.

...

Variables then to be passed in tab_plain.

na_drop_all

<tidy-select> Removes all observation with a NA in any of the chosen variables.

cleannames

Set to TRUE to clean levels names, by removing prefix numbers like "1-", and text in parentheses.

other_if_less_than

When set to a positive integer, levels with less count than it will be merged into an "Others" level.

other_level

The name of the "Other" level, as a character vector of length one.

Value

A modified data.frame.

Examples

data <- dplyr::starwars %>%
tab_prepare(sex, hair_color, gender, other_if_less_than = 5,
            na_drop_all = sex)
data

Transform chi2 attribute table of a tabxplor_tab into rows with pvalues.

Description

Transform chi2 attribute table of a tabxplor_tab into rows with pvalues.

Usage

tab_pvalue_lines(tabs)

Arguments

tabs

A tabxplor_tab (with chi2 table as attribute).

Value

A tabxplor_tab.


Spread a tab, passing a tab variable to column

Description

Spread a tab, passing a tab variable to column

Usage

tab_spread(
  tabs,
  spread_vars,
  names_prefix,
  names_sort = FALSE,
  totname = "Total"
)

Arguments

tabs

A tibble of class tab, made with tab, tab_many or tab_plain.

spread_vars

<tidy-select> The tab variables to pass to column, with a syntax of type c(var1, var2, ...).

names_prefix

String added to the start of every variable name.

names_sort

If no names_prefix is given, new names takes the form spread_var_col_var_level. Should then the column names be sorted ? If FALSE, the default, column names are ordered by first appearance.

totname

The new name of the total rows, as a single string.

Value

A tibble of class tab, with less rows and more columns.

Examples

data <- forcats::gss_cat %>% dplyr::filter(year %in% c(2000, 2014))

tabs <-
  tab(data, relig, marital, c(year, race), pct = "row", totaltab = "no",
      color = "diff", tot = "row", other_if_less_than = 30)

tabs %>%
  dplyr::select(year, race, relig, Married) %>%
  tab_spread(race)

Add totals to a tab

Description

Add totals to a tab

Usage

tab_tot(
  tabs,
  tot = c("row", "col"),
  name = "Total",
  totcol = "last",
  data = NULL
)

Arguments

tabs

A tibble of class tab, made with tab_plain or tab_many.

tot

c("col", "row") and "both" print total rows and total columns. Set to "row" or "col" to print only one type. Set to "no" to remove all totals.

name

The names of the totals, as a character vector of length one or two. Use c("Total_row", "Total_column") to set different names for rows and cols.

totcol

"last" only prints a total column for the last factor column variable. Set to "each" to print a total column for each column variable.

data

The original database used to calculate the tab : it is only useful for mean columns (of numeric variables), in order to calculate the variances of total rows, necessary to calculate confidence intervals with tab_ci.

Value

A tibble of class tab. Total rows can then be detected using is_totrow, and total columns using is_totcol.

Examples

data <- dplyr::starwars %>% tab_prepare(sex, hair_color)

data %>%
  tab_plain(sex, hair_color) %>%
  tab_tot("col", totcol = "each")

Add total table to a tab

Description

Add total table to a tab

Usage

tab_totaltab(
  tabs,
  totaltab = c("table", "line", "no"),
  name = "Ensemble",
  data = NULL
)

Arguments

tabs

A tibble of class tab, made with tab_plain or tab_many.

totaltab

If there are subtables, corresponding to the levels of tab_vars, totaltab = "table" add a complete total table. totaltab = "line" add a total table of only one row with the general total. totaltab = "no" remove any existing total table.

name

The name of the total table, as a single string.

data

The original database used to calculate the tab : it is only useful for mean columns (of numeric variables), in order to calculate the variances necessary to calculate confidence intervals with tab_ci.

Value

A tibble of class tab. Rows belonging to the total table can then be detected using is_tottab.

Examples

data <- dplyr::starwars %>%
tab_prepare(sex, hair_color, gender, other_if_less_than = 5,
            na_drop_all = sex)

data %>%
  tab_plain(sex, hair_color, gender) %>%
  tab_totaltab("line")

Wrap column names and character/factor variables.

Description

Wrap column names and character/factor variables.

Usage

tab_wrap_text(
  tabs,
  wrap_rows = 35L,
  wrap_cols = 15L,
  exdent = 1,
  whitespace_only = TRUE,
  unbreakable_spaces = TRUE,
  brk = "\n"
)

Arguments

tabs

A tabxplor_tab or a tibble .

wrap_rows

By default, rownames are wrapped when larger than 30 characters.

wrap_cols

By default, colnames are wrapped when larger than 12 characters.

exdent

On the second lines or more, the number or characters to use for indentation.

whitespace_only

Set to FALSE to wrap also on non whitespace characters.

unbreakable_spaces

Set to FALSE to keep normal spaces in text (auto-break).

brk

The string to use for linebreak : ⁠\n⁠ in text, but ⁠<br>⁠ in html.

Value

The same tabxplor_tab or tibble.

Examples

tab(forcats::gss_cat, race, marital, pct = "row", color = "diff") |>
  tab_wrap_text(wrap_rows = 5L, wrap_cols = 8L)

Excel output for tabxplor tables, with formatting and colors

Description

To modify the colors used into the Excel table, you can change the global options with set_color_style and set_color_breaks.

Usage

tab_xl(
  tabs,
  path = NULL,
  replace = FALSE,
  open = rlang::is_interactive(),
  colnames_rotation = 0,
  remove_tab_vars = TRUE,
  colwidth = 10,
  print_color_legend = TRUE,
  sheets = "auto",
  n_min = 0,
  titles,
  font_text = "DejaVu Sans Condensed",
  font_num = "DejaVu Sans",
  text_size = 10,
  text_size_headers = 9,
  text_size_subtext = 9,
  hide_near_zero = Inf,
  color_type = "text"
)

Arguments

tabs

A table made with tab, tab_many or tab_plain, or a list of such tables.

path, replace, open

The name, and possibly the path, of the Excel file to create (possibly without the .xlsx extension). Default path to temporary directory. Set global option "tabxplor.export_dir" with link[base:options]{options} to change default directory. By default replace is TRUE when path is provided, FALSE when path is not provided. Use replace = TRUE to overwrite existing files. Use open = FALSE if you don't want to automatically open the tables in Excel (or another software associated with .xlsx files).

colnames_rotation

Rotate the names of columns to an angle (in degrees).

remove_tab_vars

By default, tab_vars columns are removed to gain space. Set to FALSE to keep them.

colwidth

The standard width for numeric columns, as a number. Set to "auto" to let Excel choose.

print_color_legend

Should the color legends be printed with the subtexts ?

sheets

The Excel sheets options :

  • "tabs": a new sheet is created for each table

  • "unique": all tables are on the same sheet

  • "auto": subsequent tables with the same column vars are printed on the same sheets

n_min

The total count under which a column or row is turned pale grey because there is not enough observation for it to be significant. Default to 0 (not used).

titles

The titles of the different tables, as a character vector. When missing titles are given based on the names of the variables.

font_text, font_num

Font for text and for numbers.

text_size, text_size_headers, text_size_subtext

Font sizes of text elements.

hide_near_zero

By default all cells displayed as 0 (even rounded) turn pale grey, to make the distribution of empty cells (and other cells) more visible. Provide a number to turn grey every cell below it. Set to Inf not to use this feature.

color_type

By default, the text is colored. Set to "bg" to color the background instead.

Value

The table(s) with formatting and colors in an Excel file, as a side effect. Invisibly returns tabs.

Examples

forcats::gss_cat %>%
  tab(marital, race, pct = "row", color = "diff") %>%
  tab_xl()

Table body for class tab

Description

Table body for class tab

Usage

## S3 method for class 'tabxplor_tab'
tbl_format_body(x, setup, ...)

Arguments

x

An object of class tabxplor_tab

setup

A setup object from the table

...

Other parameters.

Value

A character vector.


Table footer for class tab

Description

Table footer for class tab

Usage

## S3 method for class 'tabxplor_tab'
tbl_format_footer(x, setup, ...)

Arguments

x

An object of class tabxplor_tab

setup

A setup object from the table

...

Other parameters.

Value

A character vector.


Table headers for class grouped tab

Description

Table headers for class grouped tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
tbl_sum(x, ...)

Arguments

x

An object of class tabxplor_tab

...

Other parameters.

Value

A table header


Table headers for class tab

Description

Table headers for class tab

Usage

## S3 method for class 'tabxplor_tab'
tbl_sum(x, ...)

Arguments

x

An object of class tabxplor_tab

...

Other parameters.

Value

A table header


ungroup method for class tabxplor_grouped_tab

Description

ungroup method for class tabxplor_grouped_tab

Usage

## S3 method for class 'tabxplor_grouped_tab'
ungroup(x, ...)

Arguments

x

A tibble of class tabxplor_grouped_tab.

...

Variables to remove from the grouping.

Value

An object of class tabxplor_tab or tabxplor_grouped_tab.


Vec_arith method for fmt

Description

Vec_arith method for fmt

Usage

## S3 method for class 'tabxplor_fmt'
vec_arith(op, x, y, ...)

## Default S3 method:
vec_arith.tabxplor_fmt(op, x, y, ...)

## S3 method for class 'tabxplor_fmt'
vec_arith.tabxplor_fmt(op, x, y, ...)

## S3 method for class 'numeric'
vec_arith.tabxplor_fmt(op, x, y, ...)

## S3 method for class 'tabxplor_fmt'
vec_arith.numeric(op, x, y, ...)

## S3 method for class 'MISSING'
vec_arith.tabxplor_fmt(op, x, y, ...)

Arguments

op

Operation to do.

x

fmt object.

y

Second object.

...

Other parameter.

Value

A fmt vector

A fmt vector

A fmt vector

A fmt vector

A fmt vector

A fmt vector

Methods (by class)

  • vec_arith.tabxplor_fmt(default): default vec_arith method for fmt

  • vec_arith.tabxplor_fmt(tabxplor_fmt): vec_arith method for fmt + fmt

  • vec_arith.tabxplor_fmt(numeric): vec_arith method for fmt + numeric

  • vec_arith.tabxplor_fmt(MISSING): vec_arith method for -fmt

Functions

  • vec_arith.numeric(tabxplor_fmt): vec_arith method for numeric + fmt


Convert fmt into character

Description

Convert fmt into character

Usage

## S3 method for class 'tabxplor_fmt'
vec_cast.character(x, to, ...)

Arguments

x

A fmt vector

to

A character vector

...

Other parameter

Value

A character vector


Convert fmt into double

Description

Convert fmt into double

Usage

## S3 method for class 'tabxplor_fmt'
vec_cast.double(x, to, ...)

Arguments

x

A fmt vector

to

A double vector

...

Other parameter.

Value

A double vector


Convert fmt into integer

Description

Convert fmt into integer

Usage

## S3 method for class 'tabxplor_fmt'
vec_cast.integer(x, to, ...)

Arguments

x

A integer vector

to

A fmt vector

...

Other parameter.

Value

An integer vector


Convert double into fmt

Description

Convert double into fmt

Usage

## S3 method for class 'tabxplor_fmt.double'
vec_cast(x, to, ...)

Arguments

x

A double vector

to

A fmt vector

...

Other parameter.

Value

A fmt vector


Convert integer into fmt

Description

Convert integer into fmt

Usage

## S3 method for class 'tabxplor_fmt.integer'
vec_cast(x, to, ...)

Arguments

x

A integer vector

to

A fmt vector

...

Other parameter.

Value

A fmt vector


Convert fmt into fmt

Description

Convert fmt into fmt

Usage

## S3 method for class 'tabxplor_fmt.tabxplor_fmt'
vec_cast(x, to, ...)

Arguments

x

A fmt vector

to

A fmt vector

...

Other parameter.

Value

A fmt vector


Vec_math method for class fmt

Description

Vec_math method for class fmt

Usage

## S3 method for class 'tabxplor_fmt'
vec_math(.fn, .x, ...)

Arguments

.fn

A function

.x

A fmt object

...

Other parameter

Value

A fmt vector


Compare with fmt vector

Description

Compare with fmt vector

Usage

## S3 method for class 'tabxplor_fmt'
vec_proxy_compare(x, ...)

Arguments

x

A fmt vector

...

Other parameter

Value

A double vector


Test equality with fmt vector

Description

Test equality with fmt vector

Usage

## S3 method for class 'tabxplor_fmt'
vec_proxy_equal(x, ...)

Arguments

x

A fmt vector

...

Other parameter

Value

A double vector


Abbreviated display name for class fmt in tibbles

Description

Abbreviated display name for class fmt in tibbles

Usage

## S3 method for class 'tabxplor_fmt'
vec_ptype_abbr(x, ...)

Arguments

x

A fmt object.

...

Other parameter.

Value

A single string with abbreviated fmt type.


Printed type for class fmt

Description

Printed type for class fmt

Usage

## S3 method for class 'tabxplor_fmt'
vec_ptype_full(x, ...)

Arguments

x

A fmt object.

...

Other parameter.

Value

A single string with full fmt type.


Find common ptype between double and fmt

Description

Find common ptype between double and fmt

Usage

## S3 method for class 'double.tabxplor_fmt'
vec_ptype2(x, y, ...)

Arguments

x

A double vector

y

A fmt vector

...

Other parameter.

Value

A fmt vector


Find common ptype between integer and fmt

Description

Find common ptype between integer and fmt

Usage

## S3 method for class 'integer.tabxplor_fmt'
vec_ptype2(x, y, ...)

Arguments

x

An integer vector

y

A fmt vector

...

Other parameter.

Value

A fmt vector


Find common ptype between fmt and double

Description

Find common ptype between fmt and double

Usage

## S3 method for class 'tabxplor_fmt.double'
vec_ptype2(x, y, ...)

Arguments

x

A fmt vector

y

A double vector

...

Other parameter.

Value

A fmt vector


Find common ptype between fmt and integer

Description

Find common ptype between fmt and integer

Usage

## S3 method for class 'tabxplor_fmt.integer'
vec_ptype2(x, y, ...)

Arguments

x

A fmt vector

y

An integer vector

...

Other parameter.

Value

A fmt vector


Find common ptype between fmt and fmt

Description

Find common ptype between fmt and fmt

Usage

## S3 method for class 'tabxplor_fmt.tabxplor_fmt'
vec_ptype2(x, y, ...)

Arguments

x

A fmt object.

y

A fmt object.

...

Other parameter.

Value

A fmt vector