Skip to contents

procR provides a unified interface for producing and disseminating statistical tables from microdata. It allows users to specify custom cross-tabulations using a convenient and intuitive syntax. Tables are computed very efficiently and can be exported as .html or .xlsx (in development).

Documentation

The pkgdown documentation of this package can be found here.

Installation

You can install the development version of procR as follows:

remotes::install_gitlab(repo = "ysaidani/procr", host = "gitlab.opencode.de")

Usage

library(procR)

# Define varformats
region_f <- new_format_asis(eusilc, var = region, add_total = TRUE)
citizenship_f <- new_format_asis(eusilc, var = citizenship, add_total = TRUE, include_na = TRUE)
gender_f <- new_format_asis(eusilc, var = gender, add_total = TRUE)
ecostat_f <- new_format(var = ecoStat, add_total = TRUE,
                        "Working",
                        ss_all(1 ~ "Working full time",
                               2 ~ "Working part time"),
                        "Not working",
                        ss_all(3 ~ "Unemployed",
                               4 ~ "Pupil, student, further training or unpaid work experience or in compulsory military/community service",
                               5 ~ "In retirement/early retirement",
                               6 ~ "Permanently disabled/unfit to work/other inactive person",
                               7 ~ "Fulfilling domestic tasks"))

# Generate table
create_table_count(df = eusilc,
                   formula = region_f + citizenship_f ~ gender_f * ecostat_f,
                   where = main == TRUE)

Details

National statistical offices routinely produce cross-tabulations of microdata - descriptive summary tables that present key indicators such as counts, sums, or means, often broken down by demographic, geographic, or socioeconomic dimensions. These tables form the backbone of official publications and data dissemination.

However, their creation is not trivial, due to requirements such as:

  • non-exclusive or non-exhaustive summaries of variables (e.g. to display sub-totals, or only selected sub-items),
  • custom grouping of variables (e.g. transforming a continuous age variable into age groups for aggregation),
  • multi-dimensional cross-tabulations (with variable combinations in rows and/or columns),
  • custom cell suppression in accordance with data confidentiality or data quality protocols (e.g. bracketing or replacing sensitive values), and
  • the generation of standardised output formats that include metadata and comply with corporate design guidelines.

Although numerous R packages address individual aspects of these needs, there is currently no comprehensive tool that facilitates the entire process of creating these tables from start to finish. In contrast, SAS procedures like PROC FORMAT, PROC TABULATE, and PROC REPORT are well-established for producing custom cross-tabulations; however, they tend to be less flexible, performant, and extensible compared to modern R solutions.

procR aims to fill this gap: It combines the flexibility and power of R with a streamlined, end-to-end workflow for creating custom tabulations of microdata, supporting all the requirements outlined above. In particular:

  1. procR offers an intuitive and R-native syntax for specifying custom variable groupings, allowing for non-exclusive and non-exhaustive categories as well as combinations of variables, thus aiding reproducibility and error reduction.
  2. Custom cross-tables are specified using a streamlined and familiar syntax inspired by PROC TABULATE.
  3. Common aggregation functions (e.g., weighted counts, means, and sums) are computed efficiently via matrix algebra and sparse matrices, allowing the package to scale exceptionally well to large datasets and complex tables. The package also supports user-defined aggregation functions, which maintain high performance through the use of the efficient collapse package.
  4. Tables can be exported to .html and .xlsx-format while implementing custom statistical disclosure control (in development).

Disclaimer

This open-source software is provided “as is” without warranty of any kind. It was developed by the author in a personal capacity. The author’s employer does not endorse the software and is not responsible for its contents or for any results obtained from its use. Users are responsible for validating results and assessing the suitability of the software for their purposes.

The package is currently in development, has several unfinished features and almost certainly contains bugs. In particular, the export features are currently rudimentary at best. Please report problems, inconsistencies, missing features and bugs by email.

Contributions

Many thanks to Elias Minther and Oliver Hauke for their contributions to the package!