{"id":16572324,"url":"https://github.com/jonocarroll/chaint","last_synced_at":"2025-03-27T17:45:16.646Z","repository":{"id":71014007,"uuid":"62592185","full_name":"jonocarroll/chaint","owner":"jonocarroll","description":"\"chain with a tee\" -- add tee functions to magrittr/dplyr chains","archived":false,"fork":false,"pushed_at":"2016-07-04T23:49:48.000Z","size":7,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T00:34:41.880Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jonocarroll.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"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":null}},"created_at":"2016-07-04T23:09:35.000Z","updated_at":"2024-03-16T04:09:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"79b0c066-04b5-417d-a676-9aaf14414363","html_url":"https://github.com/jonocarroll/chaint","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/jonocarroll%2Fchaint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonocarroll%2Fchaint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonocarroll%2Fchaint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonocarroll%2Fchaint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonocarroll","download_url":"https://codeload.github.com/jonocarroll/chaint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245897782,"owners_count":20690455,"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":[],"created_at":"2024-10-11T21:27:10.742Z","updated_at":"2025-03-27T17:45:16.641Z","avatar_url":"https://github.com/jonocarroll.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput:\n  md_document:\n    variant: markdown_github\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"README-\"\n)\nsuppressWarnings(suppressPackageStartupMessages(library(dplyr)))\n```\n# chaint\n### \"chain with a tee\" - tee functions with magrittr/dplyr chains\n\n## Installation:\n\n```\ndevtools::install_github(\"jonocarroll/chaint\")\n```\n\n## Motivation:\n\n`dplyr` chains are undoubtedly more readable than composed functions, and this makes processing of sequential steps much simpler. When written with line breaks, such as \n\n```{r}\nmtcars %\u003e% \n   group_by(cyl) %\u003e% \n   summarise(meanMPG = mean(mpg))\n```\n\nindividual processing steps can be skipped over by commenting out a single line\n\n```{r}\nmtcars %\u003e% \n#   group_by(cyl) %\u003e% \n   summarise(meanMPG = mean(mpg))\n```\n\nThe ouptut can then be viewed, and processing resumed.\n\nOften we are interested in what is happening in the middle of this chain, or would like to do something conditionally. `magrittr::%T\u003e%` provides a tee-like function which essentially boils down to\n\n```{r, eval=FALSE}\n%T\u003e% \u003c- function(lhs, rhs) {\n  do.call(rhs, lhs)\n  return(lhs)\n}\n```\nThis is useful for passing data to the `rhs` function which has side effects and for which the return value is to be discarded. However, `%T\u003e%` doesn't take arguments, and the `rhs` function is required to do something with the incomming data.\n\n`chaint` provides a similar function `tee` which is a more sophisticated version of `%T\u003e%` which\n\n - still takes the data as input to the first argument, but\n - doesn't require the data to be used in any way, \n - provides a mechanism for adding messages within a chain,\n - can be conditional on the data,\n - can take arguments to be passed on to the `rhs` function.\n    \nThis is primarily intended for interactive use, not for programming with, as it it used for the side effect of printing to console.\n\n## Example usage:\n\nTo add a simple message (maybe a checkpoint flag or a notification about the processing), use `say` with a quoted message:\n\n```{r}\nmtcars %\u003e% \n   group_by(cyl) %\u003e% \n   chaint::say(\"caution, grouped data!\") %\u003e% \n   summarise(meanMPG = mean(mpg))\n```\n\nThe `tee` function prints a message and applies a function to the incomming data (with optional arguments) then transparently returns the incomming data to allow the chain to continue, allowing inspection of the intermediate data. No commenting out of lines.\n\n```{r}\nmtcars %\u003e%\n  chaint::tee(\"checkpoint 1\", head, n=10) %\u003e%\n  filter(cyl \u003c 6) %\u003e%\n  chaint::tee(\"checkpoint 2\", head, n=3) %\u003e%\n  summarise(meanMPG = mean(mpg))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonocarroll%2Fchaint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonocarroll%2Fchaint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonocarroll%2Fchaint/lists"}