{"id":15554877,"url":"https://github.com/danchaltiel/crosstable","last_synced_at":"2025-04-12T15:33:19.817Z","repository":{"id":41114403,"uuid":"253049827","full_name":"DanChaltiel/crosstable","owner":"DanChaltiel","description":"Easy and thorough description of datasets ","archived":false,"fork":false,"pushed_at":"2025-01-20T08:49:30.000Z","size":43873,"stargazers_count":116,"open_issues_count":11,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-10T15:44:18.764Z","etag":null,"topics":["descriptive-statistics","flextable","frequency-table","html-report","msword","officer","r","rstats"],"latest_commit_sha":null,"homepage":"https://danchaltiel.github.io/crosstable/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanChaltiel.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null}},"created_at":"2020-04-04T16:46:55.000Z","updated_at":"2025-01-20T08:46:19.000Z","dependencies_parsed_at":"2023-11-11T23:23:53.024Z","dependency_job_id":"d0e1fc3e-97f4-4510-83c1-cf9997ab92eb","html_url":"https://github.com/DanChaltiel/crosstable","commit_stats":{"total_commits":1048,"total_committers":8,"mean_commits":131.0,"dds":"0.19656488549618323","last_synced_commit":"0d125fed280d58fc57f915161179e8e716d2f7c9"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanChaltiel%2Fcrosstable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanChaltiel%2Fcrosstable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanChaltiel%2Fcrosstable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanChaltiel%2Fcrosstable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanChaltiel","download_url":"https://codeload.github.com/DanChaltiel/crosstable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248589877,"owners_count":21129695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["descriptive-statistics","flextable","frequency-table","html-report","msword","officer","r","rstats"],"created_at":"2024-10-02T15:03:53.811Z","updated_at":"2025-04-12T15:33:19.796Z","avatar_url":"https://github.com/DanChaltiel.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: \n  github_document:\n    html_preview: false\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include=FALSE}\nlibrary(knitr)\nknitr::opts_chunk$set(\n  collapse=TRUE,\n  comment=\"#\u003e\",\n  fig.path=\"man/figures/README-\",\n  fig.height = 7,\n  out.width=\"100%\"\n)\nlibrary(crosstable)\ncrosstable_options(\n  crosstable_fontsize_body = 8,\n  crosstable_padding_v = 0\n)\n# options(Encoding=\"UTF-8\")\n# library(officer)\n# library(flextable)\n```\n\n\n# crosstable \u003ca href='https://DanChaltiel.github.io/crosstable/'\u003e\u003cimg src='man/figures/logo.png' align=\"right\" height=\"175\" /\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n[![Package-License](http://img.shields.io/badge/license-GPL--3-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-3.0.html) \n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)\n[![CRAN status](https://www.r-pkg.org/badges/version/crosstable)](https://CRAN.R-project.org/package=crosstable)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/crosstable?color=blue)](https://r-pkg.org/pkg/crosstable)\n[![Last Commit](https://img.shields.io/github/last-commit/DanChaltiel/crosstable)](https://github.com/DanChaltiel/crosstable)\n[![Codecov test coverage](https://codecov.io/gh/DanChaltiel/crosstable/branch/main/graph/badge.svg)](https://app.codecov.io/gh/DanChaltiel/crosstable?branch=main)\n[![R-CMD-check](https://github.com/DanChaltiel/crosstable/actions/workflows/check-standard.yaml/badge.svg?branch=main)](https://github.com/DanChaltiel/crosstable/actions/workflows/check-standard.yaml)\n[![minimal R version](https://img.shields.io/badge/R-%E2%89%A53.1-blue.svg)](https://cran.r-project.org/)\n\u003c!-- [![Dependencies](https://tinyverse.netlify.com/badge/crosstable)](https://cran.r-project.org/package=crosstable)  --\u003e\n\u003c!-- [![Build Status](https://travis-ci.org/DanChaltiel/crosstable.svg?branch=main)](https://travis-ci.org/DanChaltiel/crosstable) --\u003e\n\u003c!-- badges: end --\u003e\n\n\n\nCrosstable is a package centered on a single function, `crosstable`, which easily computes descriptive statistics on datasets. It can use the `tidyverse` syntax and is interfaced with the package `officer` to create automatized reports.\n\n## Installation\n\n```{r run-numeric-md, include=FALSE}\nlast_cran = pkgsearch::cran_package(\"crosstable\")$Version\n# last_tag = dplyr::last(names(git2r::tags()))\nlast_tag = purrr::map_dbl(git2r::tags(), ~{\n  if(is.null(.x$tagger)) return(NA)\n  as.POSIXct(.x$tagger$when)\n}) %\u003e% sort() %\u003e% names() %\u003e% dplyr::last()\ngit_head = git2r::revparse_single(git2r::repository(),\"HEAD\") #sapply(git_head, print)\nlast_commit = substr(git_head$sha, 1,7)\nout = c(\n  \"```{r install, eval=FALSE}\",\n  '# Install last version available on CRAN',\n  'install.packages(\"crosstable\")',\n  '', \n  '# Install development version on Github',\n  'devtools::install_github(\"DanChaltiel/crosstable\", build_vignettes=TRUE)',\n  '', \n  '# Install specific commit or tagged version (for reproducibility purpose)',\n  knit_expand(text='devtools::install_github(\"DanChaltiel/crosstable@{{last_commit}}\", build_vignettes=TRUE)'),\n  knit_expand(text='devtools::install_github(\"DanChaltiel/crosstable@{{last_tag}}\", build_vignettes=TRUE)'),\n\"```\"\n)\n```\n`r paste(knit(text = out), collapse = '\\n')`\n\nNote that, for reproducibility purpose, an even better solution would be to use [`renv`](https://rstudio.github.io/renv/articles/renv.html).\n\n## Overview\n\nHere are 2 examples to try and show you the main features of `crosstable`. See the [documentation website](https://danchaltiel.github.io/crosstable/) for more.\n\n#### Example #1\n\n\u003e Dear crosstable, using the `mtcars2` dataset, please describe columns `disp` and `vs` depending on the levels of column `am`, with totals in both rows and columns, and with proportions formatted with group size, percent on row and percent on column, with no decimals.\n\n```{r usage1, eval=TRUE, echo=TRUE, results=\"hide\", warning=FALSE, message=FALSE}\nlibrary(crosstable)\nct1 = crosstable(mtcars2, c(disp, vs), by=am, total=\"both\", \n                 percent_pattern=\"{n} ({p_row}/{p_col})\", percent_digits=0) %\u003e%\n  as_flextable()\nct1\n```\n\n```{r, include=FALSE}\nflextable::save_as_image(ct1, \"man/figures/ct1.png\")\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"man/figures/ct1_mod.png\" alt=\"crosstable1\"\u003e\n\u003c/p\u003e\n\nWith only a few arguments, we did select which column to describe (`c(disp, vs)`), define a grouping variable (`by=am`), set the percentage calculation in row/column (`percent_pattern=`), and ask for totals (`total=`). \n\nSince `mtcars2` is a dataset with labels, they are displayed instead of the variable name (see [here](https://danchaltiel.github.io/crosstable/articles/crosstable.html#dataset-modified-mtcars) for how to add some). \n\nAs `crosstable()` is returning a `data.frame`, we use `as_flextable()` to output a beautiful HTML table. This one can even be exported to MS Word with a few more lines of code (see [here](https://danchaltiel.github.io/crosstable/articles/crosstable-report.html) to learn how).\n\n#### Example #2\n\nHere is a more advanced example. \n\n\u003e Dear crosstable, using the `mtcars2` dataset again, please describe all columns whose name starts with \"cy\" and those whose name ends with \"at\", depending on the levels of both columns `am` and `vs`, without considering labels, applying `mean()` and `quantile()` as summary function, with `probs` 25% and 75% defined for this latter function, and with 3 decimals for numeric variables:\n\n```{r usage2, eval=TRUE, echo=TRUE, results=\"hide\", warning=FALSE, message=FALSE}\nct2 = crosstable(mtcars2, c(starts_with(\"cy\"), ends_with(\"at\")), by=c(am, vs), \n                 label=FALSE, num_digits=3, funs=c(mean, quantile), \n                 funs_arg=list(probs=c(.25,.75))) %\u003e% \n  as_flextable(compact=TRUE, header_show_n=1:2)\nct2\n```\n\n```{r, include=FALSE}\nflextable::save_as_image(ct2, \"man/figures/ct2.png\")\nfile.remove(\"man/figures/README-usage1-1.png\")\nfile.remove(\"man/figures/README-usage2-1.png\")\n```\n\n\u003cp style=\"text-align: center;\"\u003e\n  \u003cimg src=\"man/figures/ct2_mod.png\" alt=\"crosstable2\"\u003e\n\u003c/p\u003e\n\n\nHere, the variables were selected using `tidyselect` helpers and the summary functions `mean` and `quantile` were specified, along with argument `probs` for the latter. Using `label=FALSE` allowed to see which variables were selected but it is best to keep the labels in the final table. \n\nIn `as_flextable()`, the `compact=TRUE` option yields a longer output, which may be more suited in some contexts (for instance for publication), and `header_show_n=1:2` adds the group sizes for both rows of the header.\n\n## Documentation\n\nYou can find the whole documentation on the [dedicated website](https://danchaltiel.github.io/crosstable/): \n\n+ `vignette(\"crosstable\")` for a first step-by-step guide on how to use `crosstable` ([link](https://danchaltiel.github.io/crosstable/articles/crosstable.html))\n+ `vignette(\"crosstable-report\")` for more on creating MS Word reports using either `{officer}` or `Rmarkdown` ([link](https://danchaltiel.github.io/crosstable/articles/crosstable-report.html))\n+ `vignette(\"pertent_pattern\")` for more on how to use `percent_pattern` ([link](https://danchaltiel.github.io/crosstable/articles/crosstable-selection.html))\n+ `vignette(\"crosstable-selection\")` for more on variable selection ([link](https://danchaltiel.github.io/crosstable/articles/crosstable-selection.html)), although you should better read https://tidyselect.r-lib.org/articles/syntax.html.\n\n\nThere are lots of other features you can learn about there, for instance (non-exhaustive list):\n\n- description of correlation, dates, and survival data ([link](https://danchaltiel.github.io/crosstable/articles/crosstable.html#miscellaneous-1))\n- variable selection with functions, e.g. `is.numeric` ([link](https://danchaltiel.github.io/crosstable/articles/crosstable-selection.html#select-with-predicate-functions))\n- formula interface, allowing to describe more mutated columns, e.g. `sqrt(mpg)` or `Surv(time, event)` ([link](https://danchaltiel.github.io/crosstable/articles/crosstable-selection.html#select-with-a-formula))\n- automatic computation of statistical tests ([link](https://danchaltiel.github.io/crosstable/articles/crosstable.html#tests)) and of effect sizes ([link](https://danchaltiel.github.io/crosstable/articles/crosstable.html#effects))\n- global options to avoid repeating arguments ([link](https://danchaltiel.github.io/crosstable/reference/crosstable_options.html))\n\n\n\n## Getting help and giving feedback\n\nIf you have a question about how to use `crosstable`, please ask on [StackOverflow](https://stackoverflow.com/) with the tag `crosstable`. You can `@DanChaltiel` in a comment if  you are struggling to get answers. Don't forget to add a minimal **repr**oducible **ex**ample to your question, ideally using the [reprex](https://reprex.tidyverse.org/) package.\n\nIf you miss any feature that you think would belong in `crosstable`, please fill a [Feature Request](https://github.com/DanChaltiel/crosstable/issues/new/choose) issue.\n\nIf you encounter an unexpected error while using `crosstable`, please fill a [Bug Report](https://github.com/DanChaltiel/crosstable/issues/new/choose) issue. In case of any installation problem, try the solutions proposed in [this article](https://danchaltiel.github.io/crosstable/articles/crosstable-install.html) first.\n\n## Acknowledgement\n\nIn its earliest development phase, `crosstable` was based on the awesome package [`biostat2`](https://github.com/eusebe/biostat2) written by David Hajage. Thanks David!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanchaltiel%2Fcrosstable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanchaltiel%2Fcrosstable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanchaltiel%2Fcrosstable/lists"}