{"id":16472913,"url":"https://github.com/elipousson/d2r","last_synced_at":"2025-03-23T11:32:49.564Z","repository":{"id":229500268,"uuid":"776675300","full_name":"elipousson/d2r","owner":"elipousson","description":"A R package for D2 diagrams","archived":false,"fork":false,"pushed_at":"2024-10-09T04:54:02.000Z","size":7677,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T20:07:17.113Z","etag":null,"topics":["d2","r-package","visualization"],"latest_commit_sha":null,"homepage":"https://elipousson.github.io/d2r/","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/elipousson.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","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":"2024-03-24T06:44:26.000Z","updated_at":"2025-02-13T13:14:13.000Z","dependencies_parsed_at":"2024-06-26T04:23:07.327Z","dependency_job_id":"41df4831-5b1b-45e4-bee3-353fea1ee069","html_url":"https://github.com/elipousson/d2r","commit_stats":null,"previous_names":["elipousson/d2r"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipousson%2Fd2r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipousson%2Fd2r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipousson%2Fd2r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipousson%2Fd2r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elipousson","download_url":"https://codeload.github.com/elipousson/d2r/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097158,"owners_count":20560311,"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":["d2","r-package","visualization"],"created_at":"2024-10-11T12:18:57.336Z","updated_at":"2025-03-23T11:32:49.168Z","avatar_url":"https://github.com/elipousson.png","language":"R","funding_links":[],"categories":[],"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, 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# d2r\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)\n\u003c!-- badges: end --\u003e\n\nThe goal of d2r is to support the creation, reading, writing, and rendering of D2 diagrams using R.\n\nWhat is D2? From the [D2 Introduction](https://d2lang.com/tour/intro):\n\n\u003e D2 is a diagram scripting language that turns text to diagrams. It stands for Declarative Diagramming. Declarative, as in, you describe what you want diagrammed, it generates the image.\n\nI am a contributor to the [D2 Extension for Quarto](https://github.com/data-intuitive/quarto-d2) and created this package to experiment with the possibilities of native R diagram creation and rendering.\n\nNote that this package is experimental and the process for building and editing D2 diagrams is likely to change. I also hope to add a knitr engine to support d2 code blocks within a RMarkdown or Quarto document.\n\n## Installation\n\nYou can install the development version of d2r like so:\n\n``` r\n# pak::pkg_install(\"elipousson/d2r\")\n```\n\n## Examples\n\n### Setup\n\n```{r setup}\nlibrary(d2r)\n```\n\nIf d2 is installed and available on your PATH, you can check the version:\n\n```{r}\nd2_version()\n```\n\nIf you have D2 installed with Homebrew, you may have trouble rendering a diagram within a RMarkdown. If so, you may need to set an environmental variable that points to the D2 PATH.\n\nUse `d2_which()` to locate the path for the installed version of D2:\n\n```{r}\nd2_which()\n```\n\nSee this [2018 blog post by Tony Tsai](https://blog.tonytsai.name/blog/2018-05-07-setting-path-variable-for-gs-command-in-rstudio/) on trouble-shooting `PATH` variable issues for `brew`-installed commands.\n\n## Basic usage\n\n```{r}\n# Helper function for file paths\nfig_path \u003c- \\(x) {\n  paste0(knitr::opts_chunk$get(\"fig.path\"), x)\n}\n\noptions(\"d2r.pad\" = 20)\noptions(\"d2r.direction\" = \"right\")\n```\n\n\nHere is a basic example using `d2_diagram()` to create a basic diagram with two connected shapes based on a named character vector:\n\n```{r d2-diagram-example}\nsimple_diagram \u003c- d2_diagram(\n  c(\"R\" = \"D2\")\n)\n\nsimple_diagram\n```\n\n```{r simple-diagram}\nd2_include(\n  simple_diagram,\n  fig_path(\"simple_diagram.png\")\n)\n```\n\nYou can pass both named and unnamed lines of text with D2 syntax, specify connectors (used with the named elements), and set the overall direction for the diagram:\n\n```{r connected_diagram-example}\nconnected_diagram \u003c- d2_diagram(\n  c(\"R\" = \"D2\", \"D2\" = \"R\"),\n  \"R.shape: oval\",\n  \"D2.shape: square\",\n  connector = \"-\u003e\"\n)\n\nconnected_diagram\n```\n\n```{r connected_diagram}\nd2_include(\n  connected_diagram,\n  fig_path(\"connected_diagram.png\")\n)\n```\n\nThe entity-relationship diagrams and table schema can be represented using the SQL table style diagrams with `d2_sql_table()`:\n\n```{r, width='50%'}\nmtcars_tbl \u003c- d2_sql_table(mtcars[, 1:4], id = \"mtcars\")\n\nmtcars_tbl\n\nd2_include(mtcars_tbl, output = fig_path(\"mtcars.png\"))\n```\n\nYou can use `d2_render()` to convert a D2 file into a PNG, SVG, PDF, or GIF file. `d2_include()` is a wrapper for `knitr::include_graphics()` that helps to include a diagram in a Quarto or R Markdown document:\n\n```{r}\ndiagram \u003c- d2_diagram(\n  c(\n    \"Beginning\" = \"Middle\",\n    \"Middle\" = \"End\",\n    \"End\" = \"Beginning\"\n  ),\n  \"Beginning.shape: circle\",\n  \"End.shape: square\",\n  direction = \"right\"\n)\n\ndiagram\n\nd2_include(\n  diagram,\n  output = fig_path(\"include-example.png\"),\n  sketch = TRUE,\n  theme = \"Terminal\"\n)\n```\n\n## Related packages and projects\n\nQuarto extension for embedding d2 diagrams in documents:\n\n- [quarto-d2](https://github.com/data-intuitive/quarto-d2)\n\nggplot2 packages for building diagrams and network visualizations:\n\n- [ggdiagram](https://wjschne.github.io/ggdiagram/)\n- [ggflowchart](https://nrennie.rbind.io/ggflowchart/)\n- [ggraph](https://ggraph.data-imaginist.com/)\n- [ggdag](https://r-causal.github.io/ggdag/)\n\nOther network visualization packages:\n\n- [DiagrammeR](https://rich-iannone.github.io/DiagrammeR/)\n- [networkD3](https://christophergandrud.github.io/networkD3/)\n\nOther packages for working with diagrams:\n\n- [minixcali](https://baptiste.github.io/minixcali/index.html)\n\nFind more diagram-focused packages and projects in [this GitHub list](https://github.com/stars/elipousson/lists/r-diagrams).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felipousson%2Fd2r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felipousson%2Fd2r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felipousson%2Fd2r/lists"}