{"id":25806015,"url":"https://github.com/alipsa/r2md","last_synced_at":"2025-07-19T15:33:15.419Z","repository":{"id":57742912,"uuid":"325860099","full_name":"Alipsa/r2md","owner":"Alipsa","description":"A Renjin R package that converts R objects and functions into markdown text","archived":false,"fork":false,"pushed_at":"2022-08-16T17:21:56.000Z","size":125,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-01T11:27:03.038Z","etag":null,"topics":["r-package","renjin"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alipsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["Alipsa"]}},"created_at":"2020-12-31T19:15:47.000Z","updated_at":"2022-02-16T20:00:30.000Z","dependencies_parsed_at":"2022-09-11T09:41:30.525Z","dependency_job_id":null,"html_url":"https://github.com/Alipsa/r2md","commit_stats":null,"previous_names":["pernyfelt/r2md"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fr2md","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fr2md/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fr2md/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fr2md/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alipsa","download_url":"https://codeload.github.com/Alipsa/r2md/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241052529,"owners_count":19901043,"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":["r-package","renjin"],"created_at":"2025-02-27T19:52:40.150Z","updated_at":"2025-02-27T19:52:40.647Z","avatar_url":"https://github.com/Alipsa.png","language":"R","funding_links":["https://github.com/sponsors/Alipsa"],"categories":[],"sub_categories":[],"readme":"# r2md\nA Renjin R package that converts R objects and functions into markdown text or html\n\nThe approach is similar to [htmlcreator](https://github.com/perNyfelt/htmlcreator) which renders r objects directly into html\nwhereas this package renders r objects into markdown which can then be exported to html (or pdf or whatever).\n\nr2md is an integral part in the support for the *mdr* file format which is somewhat\nsimilar to *rmd* (r markdown) in the sense that it enables enhancing markdown with r code to support\n[reproducible research](https://en.wikipedia.org/wiki/Reproducibility#Reproducible_research_method); but\nwhere rmd relies on knitr and \"magic rules\" for what and how to render r code, mdr puts the responsibility \nto generate markdown text from r code on you - and using r2md this is quite a pleasant \nexperience giving you lots of control and power. \n\nThe [mdr2html](https://github.com/perNyfelt/mdr2html) package can process mdr files\nand render it as html. This is used in the [Munin](https://github.com/perNyfelt/munin)\nreports server to support mdr files as one of its supported report formats.\n\n## Example usages:\n\nadd the dependency to your dependency manager e.g.\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ese.alipsa\u003c/groupId\u003e\n    \u003cartifactId\u003er2md\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### use md.add() to build your markdown document\n```r\nlibrary(\"se.alipsa:r2md\")\nmd.clear()\nmd.add(\"# Hello\")\n```\n`md.content()` (which return the markdown as a string (character vector)) will equal `# Hello\\n`\n\n### Chained add\nAssuming the following markdown:\n\n#### Hello2\nSome text\n- bullet\n\nThis is how you can create that with r2md:\n```r\nlibrary(\"se.alipsa:r2md\")\nmd.clear()\nmd.add(\"#### Hello2\")$add(\"Some text\")$add(\"- bullet\")\n# convert the markdown to html and print it\nprint(md.asHtml())\n```\nwill result in\n```html\n\u003ch4\u003eHello2\u003c/h4\u003e\n\u003cp\u003eSome text\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003ebullet\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n### Adding a data.frame\n\nThe following table:\n\nemployee | salary | startdate | endDate\n--- | --- | --- | ---\nJohn Doe | 21000 | 2013-11-01 | 2020-01-10 00:00:00\nPeter Smith | 23400 | 2018-03-25 | 2020-04-12 12:10:13\nJane Doe | 26800 | 2017-03-14 | 2020-10-06 10:00:05\n\n...can be created as a data.frame in R and converted to markdown: \n```r\nlibrary(\"se.alipsa:r2md\")\nemployee \u003c- c('John Doe','Peter Smith','Jane Doe')\nsalary \u003c- c(21000, 23400, 26800)\nstartdate \u003c- as.Date(c('2013-11-1','2018-3-25','2017-3-14'))\nendDate \u003c- as.POSIXct(c('2020-01-10 00:00:00', '2020-04-12 12:10:13', '2020-10-06 10:00:05'), tz='UTC' )\ndf \u003c- data.frame(employee, salary, startdate, endDate)\nmd.add(df)\n```\n\n`md.content()` will equal:\n```\n\nemployee | salary | startdate | endDate\n--- | --- | --- | ---\nJohn Doe | 21000 | 2013-11-01 | 2020-01-10 00:00:00\nPeter Smith | 23400 | 2018-03-25 | 2020-04-12 12:10:13\nJane Doe | 26800 | 2017-03-14 | 2020-10-06 10:00:05\n{class=\"table\"}\n\n```\n...and `md.asHtml()` will equal:\n```html\n\u003ctable class=\"table\"\u003e\n\u003cthead\u003e\n\u003ctr\u003e\u003cth\u003eemployee\u003c/th\u003e\u003cth\u003esalary\u003c/th\u003e\u003cth\u003estartdate\u003c/th\u003e\u003cth\u003eendDate\u003c/th\u003e\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\u003ctd\u003eJohn Doe\u003c/td\u003e\u003ctd\u003e21000\u003c/td\u003e\u003ctd\u003e2013-11-01\u003c/td\u003e\u003ctd\u003e2020-01-10 00:00:00\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003ePeter Smith\u003c/td\u003e\u003ctd\u003e23400\u003c/td\u003e\u003ctd\u003e2018-03-25\u003c/td\u003e\u003ctd\u003e2020-04-12 12:10:13\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eJane Doe\u003c/td\u003e\u003ctd\u003e26800\u003c/td\u003e\u003ctd\u003e2017-03-14\u003c/td\u003e\u003ctd\u003e2020-10-06 10:00:05\u003c/td\u003e\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n```\n\n### Links\nAdding links is just as expected: i.e. [Google](http://www.google.se) can be created\n\n```r\nmd.clear()\nmd.add(\"[Google](http://www.google.se)\")\n```\n... and when rendered as html it will result in\n\n```html\n\u003cp\u003e\u003ca href=\"http://www.google.se\"\u003eGoogle\u003c/a\u003e\u003c/p\u003e\n\n```\n\n### Images\nAn image such as:\n\n![Tree](https://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg)\n\ncan be referenced using \n```r\nmd.clear()\nmd.add(\"[Tree](https://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg)\")\n```\nor, alternatively:\n\n```r\nmd.clear()\nmd.add(md.imgUrl(\"https://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg\", alt=\"Tree\"))\n```\nThis latter form is useful if you want to add attributes e.g:\n\n```r\nmd.clear()\nmd.add(md.imgUrl(\"https://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg\", attr=list(id = \"mystyle\", class = \"image\")))\n```\nmd.content() will give you\n`![](https://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg){id = 'mystyle', class = 'image'}\\n`\n\n...and md.asHtml() will result in\n```html\n\u003cp\u003e\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg\" alt=\"\" id=\"mystyle\" class=\"image\" /\u003e\u003c/p\u003e\n\n```\n\nIf you want to embed the image content in the file itself (e.g. to create self contained single html files)\nyou can use md.imgEmbed(fileNameOrUrl) to convert the file or url content to a base64 string, e.g:\n```r\nmd.clear()\nmd.add(md.imgEmbed(\"https://upload.wikimedia.org/wikipedia/commons/d/dd/Accounting-icon.png\"))\n```\nmd.content() will be: `![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAABNCAAAAADGYrZsAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gkeAAohA+PvmwAAAMhJREFUWMPtmFEOwiAQRBlKxSt4/zOaolbGDw1qIyEkm0jS2fSnKX3ZwsvSBScfo0eYQsj3if5wjAF+goNnJtdlSbc1LZdzWrNrBuarMwsA2ZDmnWXsiMbdfCksaaGYVx/DftrnK6DsFW1rSKX+9RnYoLHPQa2pqmXD3v5ShrqYoT+ButEw3QFhOm+zaW7Z1BCa0vLANNUQ0fZK4x9yo1ZBtG4aNW+iiSbaj3/ycTsj6qRxhNzw1R2CzwuvTeV9U55w00yiDAPdA+74PJ7jCTFiAAAAAElFTkSuQmCC)\\n`\n\n...and md.asHtml() will be: \n```html\n\u003cp\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAABNCAAAAADGYrZsAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gkeAAohA+PvmwAAAMhJREFUWMPtmFEOwiAQRBlKxSt4/zOaolbGDw1qIyEkm0jS2fSnKX3ZwsvSBScfo0eYQsj3if5wjAF+goNnJtdlSbc1LZdzWrNrBuarMwsA2ZDmnWXsiMbdfCksaaGYVx/DftrnK6DsFW1rSKX+9RnYoLHPQa2pqmXD3v5ShrqYoT+ButEw3QFhOm+zaW7Z1BCa0vLANNUQ0fZK4x9yo1ZBtG4aNW+iiSbaj3/ycTsj6qRxhNzw1R2CzwuvTeV9U55w00yiDAPdA+74PJ7jCTFiAAAAAElFTkSuQmCC\" alt=\"\" /\u003e\u003c/p\u003e\n\n```\n### Plots\n\nThe embedded technique is also used for plots. Behind the scenes the plot is exported to a png file which is\nthen embedded using the same technique as for md.imgEmbed(). \nHere is an example of a barplot:\n\n```r\nmd.clear()\nmd.add(\"# Plot\")\nmd.plot(\n  {\n    plot(mtcars$mpg ~ mtcars$hp)\n    abline(h = mean(mtcars$mpg))\n  }, \n  width=350, \n  alt=\"mtcars mpg ~ hp\", \n  attr=list(class=\"plot1\", title=\"This is an important graph!\"), \n  height=400\n)\n```\n\nNote that md.plot() takes an anonymous code block `{ }` as the argument where you add all the plotting functions you need. \nAll additional arguments except alt and attr (width and height in this case, I put them first and last to illustrate that the \nplacement is not important) goes to the `png()` function. \n\nThe md.content() will return something like this for the above plot:\n```\n# Plot\n\n![mtcars mpg ~ hp](data:image/png;base64,\u003clong base64 string\u003e){class=\"plot1\" title=\"This is an important graph!\"}\n\n```\n\n### Convenience methods\n\n#### md.summary()\nThe md.summary provides a nice way to display a summary in tabular format. It does the following:\n```r\n  summaryDf \u003c- do.call(cbind, lapply(x, summary))\n  summaryDf \u003c- data.frame( names = row.names(summaryDf),summaryDf)\n  md.add(summaryDf, ...)\n```\n\n\n# Main 3:rd party libraries used\n\n- [Renjin](https://www.renjin.org/)\n    The R implementation for the JVM for which this extension (package) is for.\n- [commons-io](https://commons.apache.org/proper/commons-io/)\n    Used for some IO tasks such as downloading the content of a URL\n- [Flexmark](https://github.com/vsch/flexmark-java)\n    Used to render markdown into html\n  \nSee the [pom.xml](https://github.com/perNyfelt/r2md/blob/main/pom.xml) for more details.\n\n# Version history\n\n### 1.0.5\n\n### 1.0.4, 2022-08-16\n- add automatic module name to manifest\n- upgrade maven plugins\n- Add explicit dependency on ic4j to force upgrade to non CVE affected version\n- require jdk 11\n\n### 1.0.3, 2021-12-27\n- add md.renderPdf() to enable export to a PDF (it is pretty crude: you might have issues with overflowing margins\n  and non latin1 characters might be rendered as # instead.)\n- add class=\"table\" to tables if not present\n- add md.plot as a better name for md.addPlot\n- add md.summary() to provide a nice way to get pretty summaries.\n\n### 1.0.2, 2021-12-19\n- change the md.add generic to match `ANY` object and defer matching to the Markdown class\n- add support for prettier rendering of htest classes (e.g t.test output) similar to how it prints to the console\n\n### 1.0.1, 2021-12-08\n- add md.addPlot to allow more flexibility\n- update junit and maven enforcer plugin versions.\n- Fix bug in md.imgEmbed for external resources, add additional tests\n- Fix bug in getting content from a StringArrayVector\n\n### 1.0, 2021-Jan-08\nInitial version. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fr2md","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falipsa%2Fr2md","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fr2md/lists"}