tab_xl_confidential {tabxplor}R Documentation

Excel output for tabxplor tables with confidentiality rules.

Description

Excel output for tabxplor tables, with colors to show if counts and percentages respect statistical confidentiality rules. Don't forget to provide subtext = c("Source : description of the source of the data") in tab or tab_many, otherwise it is not possible to assess, for your reader, which confidentiality rules applies. For the same reason, you must supply a description of all variables in var_labels.

Usage

tab_xl_confidential(
  tabs,
  path = NULL,
  replace = NULL,
  open = rlang::is_interactive(),
  n_min = 5,
  pct_max = 0.95,
  recalculate_totcols = NULL,
  var_labels = character(),
  colnames_rotation = 0,
  colwidth = 10,
  sheets = "unique",
  print_color_legend = TRUE,
  titles,
  hide_near_zero = "auto",
  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).

n_min

The total count under which a column or row doesnt respect statistical confidentiality. Default to 5.

pct_max

The row or column percentage above which, knowing the column category, it becomes possible to guess the row category, or the other way round. Default to 0.95 (95%).

recalculate_totcols

By default, total columns are recalculated from counts if there are many col_vars but only one total column. Provide a logical vector the length of the number of tables, or a single logical, to choose the wanted behavior. The fastest way to do it is to use tab_many() with totcol = "each" before.

var_labels

The description of all the variables, necessary to assess that the tables don't break confidentiality rules, as a character vector of the type c('variable1' = 'description of the variable', 'variable2' = ...)

colnames_rotation

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

colwidth

The standard width for numeric columns, as a number. Default to 10.

sheets

The Excel sheets options :

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

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

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

print_color_legend

Should the color legends be printed with the subtexts ?

titles

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

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(race, marital, year, pct = "row", color = "diff",
     subtext = c('Source : National Opinion Research Center, General Social Survey.')) |>
  tab_xl_confidential(titles = "Marital status by race",
     var_labels = c("marital" = "marital status", "race" = "race",
     "year" = "year of survey"))
  

[Package tabxplor version 1.1.3 Index]