{"id":13400914,"url":"https://github.com/elbersb/tidylog","last_synced_at":"2025-06-13T05:32:02.843Z","repository":{"id":50308439,"uuid":"160428551","full_name":"elbersb/tidylog","owner":"elbersb","description":"Tidylog provides feedback about dplyr and tidyr operations. It provides wrapper functions for the most common functions, such as filter, mutate, select, and group_by, and provides detailed output for joins.","archived":false,"fork":false,"pushed_at":"2024-06-11T18:46:06.000Z","size":165,"stargazers_count":595,"open_issues_count":6,"forks_count":26,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-23T03:07:11.067Z","etag":null,"topics":["dplyr","r","tidyr","tidyverse","wrapper-functions"],"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/elbersb.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":"2018-12-04T22:45:53.000Z","updated_at":"2025-05-06T22:59:39.000Z","dependencies_parsed_at":"2024-06-11T22:35:25.951Z","dependency_job_id":null,"html_url":"https://github.com/elbersb/tidylog","commit_stats":{"total_commits":121,"total_committers":6,"mean_commits":"20.166666666666668","dds":0.06611570247933884,"last_synced_commit":"a18f0e920c1f0337f575301804fdea47e5021012"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/elbersb/tidylog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbersb%2Ftidylog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbersb%2Ftidylog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbersb%2Ftidylog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbersb%2Ftidylog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elbersb","download_url":"https://codeload.github.com/elbersb/tidylog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbersb%2Ftidylog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259588758,"owners_count":22880845,"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":["dplyr","r","tidyr","tidyverse","wrapper-functions"],"created_at":"2024-07-30T19:00:56.872Z","updated_at":"2025-06-13T05:32:02.810Z","avatar_url":"https://github.com/elbersb.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, 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# tidylog\n\n[![CRAN Version](https://www.r-pkg.org/badges/version/tidylog)](https://CRAN.R-project.org/package=tidylog)\n[![Downloads](http://cranlogs.r-pkg.org/badges/tidylog)](https://CRAN.R-project.org/package=tidylog)\n[![R-CMD-check](https://github.com/elbersb/tidylog/workflows/R-CMD-check/badge.svg)](https://github.com/elbersb/tidylog/actions)\n[![Coverage status](https://codecov.io/gh/elbersb/tidylog/branch/master/graph/badge.svg)](https://app.codecov.io/github/elbersb/tidylog?branch=master)\n\nThe goal of tidylog is to provide feedback about dplyr and tidyr operations. It provides simple wrapper functions for almost all dplyr and tidyr functions, such as `filter`, `mutate`, `select`, `full_join`, and `group_by`.\n\n## Example\n\nLoad `tidylog` after `dplyr` and/or `tidyr`:\n\n```{r message=FALSE, warning=FALSE}\nlibrary(\"dplyr\")\nlibrary(\"tidyr\")\nlibrary(\"tidylog\", warn.conflicts = FALSE)\n```\n\nTidylog will give you feedback, for instance when filtering a data frame or adding a new variable:\n\n```{r}\nfiltered \u003c- filter(mtcars, cyl == 4)\nmutated \u003c- mutate(mtcars, new_var = wt ** 2)\n```\n\nTidylog reports detailed information for joins:\n\n```{r}\njoined \u003c- left_join(nycflights13::flights, nycflights13::weather,\n    by = c(\"year\", \"month\", \"day\", \"origin\", \"hour\", \"time_hour\"))\n```\n\nIn this case, we see that 1,556 rows from the `flights` dataset do not have weather information.\n\nTidylog can be especially helpful in longer pipes:\n\n```{r}\nsummary \u003c- mtcars %\u003e%\n    select(mpg, cyl, hp, am) %\u003e%\n    filter(mpg \u003e 15) %\u003e%\n    mutate(mpg_round = round(mpg)) %\u003e%\n    group_by(cyl, mpg_round, am) %\u003e%\n    tally() %\u003e%\n    filter(n \u003e= 1)\n```\nHere, it might have been accidental that the last `filter` command had no effect.\n\n## Installation\n\nDownload from CRAN:\n\n``` r\ninstall.packages(\"tidylog\")\n```\n\nOr install the development version:\n\n``` r\ndevtools::install_github(\"elbersb/tidylog\")\n```\n\n## Benchmarks\n\nTidylog will add a small overhead to each function call. This can be relevant for very large datasets and especially for joins. If you want to switch off tidylog for a single long-running command, simply prefix `dplyr::` or `tidyr::`, such as in `dplyr::left_join`. See [this vignette](https://cran.r-project.org/package=tidylog/vignettes/benchmarks.html) for more information.\n\n## More examples\n\n### filter, distinct, drop_na\n\n```{r}\na \u003c- filter(mtcars, mpg \u003e 20)\nb \u003c- filter(mtcars, mpg \u003e 100)\nc \u003c- filter(mtcars, mpg \u003e 0)\nd \u003c- filter_at(mtcars, vars(starts_with(\"d\")), any_vars((. %% 2) == 0))\ne \u003c- distinct(mtcars)\nf \u003c- distinct_at(mtcars, vars(vs:carb))\ng \u003c- top_n(mtcars, 2, am)\ni \u003c- sample_frac(mtcars, 0.5)\n\nj \u003c- drop_na(airquality)\nk \u003c- drop_na(airquality, Ozone)\n```\n\n### mutate, transmute, replace_na, fill\n\n```{r}\na \u003c- mutate(mtcars, new_var = 1)\nb \u003c- mutate(mtcars, new_var = runif(n()))\nc \u003c- mutate(mtcars, new_var = NA)\nd \u003c- mutate_at(mtcars, vars(mpg, gear, drat), round)\ne \u003c- mutate(mtcars, am_factor = as.factor(am))\nf \u003c- mutate(mtcars, am = as.ordered(am))\ng \u003c- mutate(mtcars, am = ifelse(am == 1, NA, am))\nh \u003c- mutate(mtcars, am = recode(am, `0` = \"zero\", `1` = NA_character_))\n\ni \u003c- transmute(mtcars, mpg = mpg * 2, gear = gear + 1, new_var = vs + am)\n\nj \u003c- replace_na(airquality, list(Solar.R = 1))\nk \u003c- fill(airquality, Ozone)\n```\n\n### joins\n\nFor joins, tidylog provides more detailed information. For any join,\ntidylog will show the number of rows\nthat are only present in x (the first dataframe), only present in y (the second dataframe),\nand rows that have been matched. Numbers in parentheses indicate that these rows are not\nincluded in the result. Tidylog will also indicate whether any rows were duplicated\n(which is often unintentional):\n\n```{r}\nx \u003c- tibble(a = 1:2)\ny \u003c- tibble(a = c(1, 1, 2), b = 1:3) # 1 is duplicated\nj \u003c- left_join(x, y, by = \"a\")\n```\n\nMore examples:\n\n```{r}\na \u003c- left_join(band_members, band_instruments, by = \"name\")\nb \u003c- full_join(band_members, band_instruments, by = \"name\")\nc \u003c- anti_join(band_members, band_instruments, by = \"name\")\n```\n\nBecause tidylog needs to perform two additional joins behind the scenes to report this information,\nthe overhead will be larger than for the other tidylog functions (especially with large datasets).\n\n### select, relocate, rename\n\n```{r}\na \u003c- select(mtcars, mpg, wt)\nb \u003c- select_if(mtcars, is.character)\nc \u003c- relocate(mtcars, hp)\nd \u003c- select(mtcars, a = wt, b = mpg)\n\ne \u003c- rename(mtcars, miles_per_gallon = mpg)\nf \u003c- rename_with(mtcars, toupper)\n```\n\n### summarize\n\n```{r}\na \u003c- mtcars %\u003e%\n    group_by(cyl, carb) %\u003e%\n    summarize(total_weight = sum(wt))\n\nb \u003c- iris %\u003e%\n    group_by(Species) %\u003e%\n    summarize_all(list(min, max))\n```\n\n### tally, count, add_tally, add_count\n\n```{r}\na \u003c- mtcars %\u003e% group_by(gear, carb) %\u003e% tally\nb \u003c- mtcars %\u003e% group_by(gear, carb) %\u003e% add_tally()\n\nc \u003c- mtcars %\u003e% count(gear, carb)\nd \u003c- mtcars %\u003e% add_count(gear, carb, name = \"count\")\n```\n\n### pivot_longer, pivot_wider\n\n```{r}\nlonger \u003c- mtcars %\u003e%\n    mutate(id = 1:n()) %\u003e%\n    pivot_longer(-id, names_to = \"var\", values_to = \"value\")\nwider \u003c- longer %\u003e%\n    pivot_wider(names_from = var, values_from = value)\n```\n\nTidylog also supports `gather` and `spread`.\n\n## Turning logging off, registering additional loggers\n\nTo turn off the output for just a particular function call, you can simply call the dplyr and tidyr functions\ndirectly, e.g. `dplyr::filter` or `tidyr::drop_na`.\n\nTo turn off the output more permanently, set the global option `tidylog.display` to an empty list:\n\n```{r}\noptions(\"tidylog.display\" = list())  # turn off\na \u003c- filter(mtcars, mpg \u003e 20)\n\noptions(\"tidylog.display\" = NULL)    # turn on\na \u003c- filter(mtcars, mpg \u003e 20)\n```\n\nThis option can also be used to register additional loggers. The option `tidylog.display` expects\na list of functions. By default (when `tidylog.display` is set to NULL), tidylog\nwill use the `message` function to display the output, but if you prefer a more colorful output,\nsimply overwrite the option:\n\n```{r}\nlibrary(\"crayon\")  # for terminal colors\ncrayon \u003c- function(x) cat(red$bold(x), sep = \"\\n\")\noptions(\"tidylog.display\" = list(crayon))\na \u003c- filter(mtcars, mpg \u003e 20)\n```\n\nTo print the output both to the screen and to a file, you could use:\n\n```{r}\nlog_to_file \u003c- function(text) cat(text, file = \"log.txt\", sep = \"\\n\", append = TRUE)\noptions(\"tidylog.display\" = list(message, log_to_file))\na \u003c- filter(mtcars, mpg \u003e 20)\n```\n\n## Namespace conflicts\n\nTidylog redefines several of the functions exported by dplyr and tidyr, so it should be loaded last, otherwise there will be no output. A more explicit way to resolve namespace conflicts is to use the [conflicted](https://CRAN.R-project.org/package=conflicted) package:\n\n``` r\nlibrary(\"dplyr\")\nlibrary(\"tidyr\")\nlibrary(\"tidylog\")\nlibrary(\"conflicted\")\nfor (f in getNamespaceExports(\"tidylog\")) {\n    conflicted::conflict_prefer(f, \"tidylog\", quiet = TRUE)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felbersb%2Ftidylog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felbersb%2Ftidylog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felbersb%2Ftidylog/lists"}