{"id":13400474,"url":"https://github.com/romainfrancois/dance","last_synced_at":"2025-04-13T00:42:26.172Z","repository":{"id":66313291,"uuid":"172131257","full_name":"romainfrancois/dance","owner":"romainfrancois","description":"tibble() dancing 💃","archived":false,"fork":false,"pushed_at":"2019-11-20T08:19:25.000Z","size":438,"stargazers_count":45,"open_issues_count":17,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-13T00:42:21.223Z","etag":null,"topics":["dance","dplyr","r","rstats","tibble"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/romainfrancois.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":null}},"created_at":"2019-02-22T20:37:36.000Z","updated_at":"2025-03-13T20:45:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"2a5d211d-61ef-45de-a8ce-689f00132819","html_url":"https://github.com/romainfrancois/dance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainfrancois%2Fdance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainfrancois%2Fdance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainfrancois%2Fdance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainfrancois%2Fdance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romainfrancois","download_url":"https://codeload.github.com/romainfrancois/dance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650417,"owners_count":21139672,"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":["dance","dplyr","r","rstats","tibble"],"created_at":"2024-07-30T19:00:52.425Z","updated_at":"2025-04-13T00:42:26.151Z","avatar_url":"https://github.com/romainfrancois.png","language":"R","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# dance \u003cimg src=\"man/figures/logo.png\" align=\"right\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle Status](https://img.shields.io/badge/lifecycle-experimental-blue.svg)](https://www.tidyverse.org/lifecycle/)\n[![Travis build status](https://travis-ci.org/romainfrancois/dance.svg?branch=master)](https://travis-ci.org/romainfrancois/dance)\n\u003c!-- badges: end --\u003e\n\n![](https://media.giphy.com/media/mnLGTXoWVzAfm/giphy.gif)\n\nDancing `r emo::ji(\"woman_dancing\")` with the stats, aka `tibble()` dancing `r emo::ji(\"man_dancing\")`. \n`dance` is a sort of reinvention of `dplyr` classic verbs, with a more modern stack \nunderneath, i.e. it leverages a lot from `vctrs` and `rlang`. \n\n# Installation\n\nYou can install the development version from GitHub.\n\n```{r, eval=FALSE}\n# install.packages(\"pak\")\npak::pkg_install(\"romainfrancois/dance\")\n```\n\n# Usage\n\nWe'll illustrate tibble dancing with `iris` grouped by `Species`. \n\n```{r example}\nlibrary(dance)\ng \u003c- iris %\u003e% group_by(Species)\n\n```\n\n### waltz(), polka(), tango(), charleston()\n\nThese are in the neighborhood of `dplyr::summarise()`. \n\n`waltz()` takes a grouped tibble and a list of formulas and returns a tibble with: \nas many columns as supplied formulas, one row per group. It does not prepend the grouping \nvariables (see `tango` for that). \n  \n```{r}\ng %\u003e% \n  waltz(\n    Sepal.Length = ~mean(Sepal.Length), \n    Sepal.Width  = ~mean(Sepal.Width)\n  )\n```\n\n`polka()` deals with peeling off one layer of grouping: \n\n```{r}\ng %\u003e% \n  polka()\n```\n\n`tango()` binds the results of `polka()` and `waltz()` so is the closest to \n`dplyr::summarise()` \n\n```{r}\ng %\u003e% \n  tango(\n    Sepal.Length = ~mean(Sepal.Length), \n    Sepal.Width  = ~mean(Sepal.Width)\n  )\n```\n\n`charleston()` is like `tango` but it packs the new columns in a tibble: \n\n```{r}\ng %\u003e% \n  charleston(\n    Sepal.Length = ~mean(Sepal.Length), \n    Sepal.Width  = ~mean(Sepal.Width)\n  )\n```\n\n\n### swing, twist\n\nThere is no `waltz_at()`, `tango_at()`, etc ... but instead we can use \neither the same function on a set of columns or a set of functions on the same column. \n\nFor this, we need to learn new dance moves: \n\n`swing()` and `twist()` are for applying the same function to a set \nof columns: \n\n```{r}\nlibrary(tidyselect)\n\ng %\u003e% \n  tango(swing(mean, starts_with(\"Petal\")))\n\ng %\u003e% \n  tango(data = twist(mean, starts_with(\"Petal\")))\n```\n\nThey differ in the type of column is created and how to name them: \n\n - `swing()` makes as many new columns as are selected by the tidy selection, and \n   the columns are named using a `.name` glue pattern, this way we might `swing()`\n   several times. \n   \n```{r}\ng %\u003e% \n  tango(\n    swing(mean, starts_with(\"Petal\"), .name = \"mean_{var}\"), \n    swing(median, starts_with(\"Petal\"), .name = \"median_{var}\"), \n  )\n```\n\n - `twist()` instead creates a single data frame column. \n \n```{r}\ng %\u003e% \n  tango(\n    mean   = twist(mean, starts_with(\"Petal\")), \n    median = twist(median, starts_with(\"Petal\")), \n  )\n```\n\nThe first arguments of `swing()` and `twist()` are either a function or a \nformula that uses `.` as a placeholder. Subsequent arguments are \ntidyselect selections. \n\nYou can combine `swing()` and `twist()` in the same `tango()` or `waltz()`: \n\n```{r}\ng %\u003e% \n  tango(\n    swing(mean, starts_with(\"Petal\"), .name = \"mean_{var}\"), \n    median = twist(median, contains(\".\"))\n  )\n```\n\n### rumba, zumba\n\nSimilarly `rumba()` can be used to apply several functions to a single column. \n`rumba()` creates single columns and `zumba()` packs them into a data frame column. \n\n```{r}\ng %\u003e% \n  tango(\n    rumba(Sepal.Width, mean = mean, median = median, .name = \"Sepal_{fun}\"), \n    Petal = zumba(Petal.Width, mean = mean, median = median)\n  )\n```\n\n### salsa, chacha, samba, madison\n\nNow we enter the realms of `dplyr::mutate()` with: \n\n - `salsa()` : to create new columns\n - `chacha()`: to reorganize a grouped tibble so that data for each group is contiguous\n - `samba()` : `chacha()` + `salsa()` \n\n```{r}\ng %\u003e% \n  salsa(\n    Sepal = ~Sepal.Length * Sepal.Width, \n    Petal = ~Petal.Length * Petal.Width\n  )\n```\n\nYou can `swing()`, `twist()`, `rumba()` and `zumba()` here too, and if you\nwant the original data, you can use `samba()` instead of `salsa()`: \n\n```{r}\ng %\u003e% \n  samba(centered = twist(~ . - mean(.), everything(), -Species))\n```\n\n`madison()` packs the columns `salsa()` would have created\n\n```{r}\ng %\u003e% \n  madison(swing(~ . - mean(.), starts_with(\"Sepal\")))\n```\n\n\n### bolero and mambo\n\n`bolero()` is similar to `dplyr::filter()`. \nThe formulas may be made by `mambo()` if you want to apply the same \npredicate to a tidyselection of columns: \n\n```{r}\ng %\u003e% \n  bolero(~Sepal.Width \u003e 4)\n\ng %\u003e% \n  bolero(mambo(~. \u003e 4, starts_with(\"Sepal\")))\n\ng %\u003e% \n  bolero(mambo(~. \u003e 4, starts_with(\"Sepal\"), .op = or))\n```\n\n","funding_links":[],"categories":["R","Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromainfrancois%2Fdance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromainfrancois%2Fdance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromainfrancois%2Fdance/lists"}