{"id":13400925,"url":"https://github.com/r-lib/debugme","last_synced_at":"2025-04-04T19:12:59.978Z","repository":{"id":54321722,"uuid":"69169722","full_name":"r-lib/debugme","owner":"r-lib","description":"Easy and efficient debugging for R packages","archived":false,"fork":false,"pushed_at":"2024-08-28T13:33:49.000Z","size":2290,"stargazers_count":152,"open_issues_count":23,"forks_count":10,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-31T15:25:36.297Z","etag":null,"topics":["debugging-tool","r"],"latest_commit_sha":null,"homepage":"https://r-lib.github.io/debugme/","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/r-lib.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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-09-25T14:36:52.000Z","updated_at":"2025-02-22T22:06:16.000Z","dependencies_parsed_at":"2024-01-18T11:03:56.341Z","dependency_job_id":"356f5950-ea3b-4573-8097-834ccf8078e5","html_url":"https://github.com/r-lib/debugme","commit_stats":{"total_commits":59,"total_committers":4,"mean_commits":14.75,"dds":"0.15254237288135597","last_synced_commit":"e7df79832c908b50e63896aa9873a04b1b2b0e4f"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fdebugme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fdebugme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fdebugme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fdebugme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-lib","download_url":"https://codeload.github.com/r-lib/debugme/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234923,"owners_count":20905854,"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":["debugging-tool","r"],"created_at":"2024-07-30T19:00:56.948Z","updated_at":"2025-04-04T19:12:59.955Z","avatar_url":"https://github.com/r-lib.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"\n```{r, setup, echo = FALSE, message = FALSE}\nknitr::opts_chunk$set(\n  comment = \"#\u003e\",\n  tidy = FALSE,\n  error = FALSE,\n  fig.width = 8,\n  fig.height = 8)\n```\n\n# debugme\n\n\u003e Debug R Packages\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/r-lib/debugme/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/debugme/actions/workflows/R-CMD-check.yaml)\n[![](https://www.r-pkg.org/badges/version/debugme)](https://www.r-pkg.org/pkg/debugme)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/debugme)](https://www.r-pkg.org/pkg/debugme)\n[![Codecov test coverage](https://codecov.io/gh/r-lib/debugme/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/debugme?branch=main)\n\u003c!-- badges: end --\u003e\n\nSpecify debug messages as special string constants, and control debugging of\npackages via environment variables. This package was largely influenced by\nthe [`debug` npm package](https://github.com/debug-js/debug).\n\n## Installation and Usage\n\nStable version:\n\n```{r eval = FALSE}\ninstall.packages(\"debugme\")\n```\n\nTo install the development version:\n\n```{r eval = FALSE}\npak::pak(\"r-lib/debugme\")\n```\n\nTo use `debugme` in your package, import it, and then add the following\n`.onLoad` function to your package:\n```r\n.onLoad \u003c- function(libname, pkgname) {\n  debugme::debugme()\n}\n```\n\nYou can now add debug messages via character literals. No function calls\nare necessary. For example:\n```r\n\"!DEBUG Start up phantomjs\"\nprivate$start_phantomjs(phantom_debug_level)\n\n\"!DEBUG Start up shiny\"\nprivate$start_shiny(path)\n\n\"!DEBUG create new phantomjs session\"\nprivate$web \u003c- session$new(port = private$phantom_port)\n\n\"!DEBUG navigate to Shiny app\"\nprivate$web$go(private$get_shiny_url())\n```\n\nThe string literals are simply ignored when debugging is turned off. To\nturn on debugging for a package, set the environment variable `DEBUGME` to\nthe package name you want to debug. E.g. from a `bash` shell:\n\n```sh\nexport DEBUGME=mypackage\n```\n\nOr from within R:\n\n```r\nSys.setenv(DEBUGME = \"mypackage\")\n```\n\nSeparate multiple package names with commas:\n\n```sh\nexport DEBUGME=mypackage,otherpackage\n```\n\nThe debug messages will be prefixed by the package names, and assuming your\nterminal supports color, will be colored differently for each package.\n\n## Example\n\n![](/screencast.gif)\n\n## Dynamic code\n\nThe `debugme` debug strings may contain R code between backticks.\nThis code is evaluated at runtime, if debugging is turned on. A single\ndebug string may contain multiple backticked code chunks:\n\n```r\n\"!DEBUG x = `x`, y = `y`\"\nif (x != y) {\n...\n```\n\n## Motivation\n\nI have always wanted a debugging tool that\n* is very simple to use,\n* can be controlled via environment variables, without changing anything\n  it the packages themselves,\n* has zero impact on performance when debugging is off.\n\n`debugme` is such a tool.\n\n### Performance\n\nFunction calls are relatively cheap in R, but they still do have an impact.\nIf you never want to worry about the log messages making your code slower,\nyou will like `debugme`. `debugme` debug strings have practically no\nperformance penalty when debugging is off.\n\nHere is a simple comparison to evaluate debugging overhead with a function call, `f1()`,\ndebugging with debug strings, `f2()`, and no debugging at all.\n\n```{r}\ndebug \u003c- function(msg) { }\nf1 \u003c- function() {\n  for (i in 1:100) {\n    debug(\"foobar\")\n    # Avoid optimizing away the loop\n    i \u003c- i + 1\n  }\n}\n```\n\n```{r}\nf2 \u003c- function() {\n  for (i in 1:100) {\n    \"!DEBUG foobar\"\n    # Avoid optimizing away the loop\n    i \u003c- i + 1\n  }\n}\n```\n\n```{r}\nf3 \u003c- function() {\n  for (i in 1:100) {\n    # Avoid optimizing away the loop\n    i \u003c- i + 1\n  }\n}\n```\n\n```{r}\nmicrobenchmark::microbenchmark(f1(), f2(), f3())\n```\n\n## License\n\nMIT © [Gábor Csárdi](https://github.com/gaborcsardi)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fdebugme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-lib%2Fdebugme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fdebugme/lists"}