Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

writes RMarkdown (.Rmd) files to MDX (.mdx) format. Used for R ➡️ RMarkdown ➡️ Markdown ➡️ MDX ➡️ JS ➡️ Gatsby blog

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

RobertMyles/writeMDX

Repository files navigation

writeMDX writes Rmarkdown (.Rmd) files toMDX. Nice and simple 😎

Install 👐

You can install it withremotes::install_github("RobertMyles/writeMDX").

Use 👇

With a file named “heyho.Rmd”:

writeMDX("heyho.Rmd")

If you’d like to use it from the command line, first runwriteMDX::cli(). Then it’s just:

writeMDX heyho.Rmd

writeMDX has a few defaults that are set up for me, but you can easilychange them. Theconfig argument accepts a list of two named lists:inlcude andexclude. These are the fields you’d like to remove, orfor which you want to check for inclusion on the YAML header. Thecommand line version isn’t set up to take anything other than thedefaults yet.

Example

I use this for my blog, for examplehere.

My workflow for mywebsite isusually:

  • Open up new Rmarkdown document in RStudio;
  • Write something kewlz about R;
  • Do some repetitive boring stuff to get it into a suitable format forrendering withGatsby.js.

writeMDX helps with that last part. Let’s say we open up a new .Rmd inRStudio, it will look like this in the YAML header (unless you use atemplate or some other format):

---title: "MDXtest"author: "Robert McDonnell"date: "2/29/2020"output: html_documentfeaturedImage: "image/png.png"---

Well, it probably won’t say"Robert McDonnell", but you get the idea.featuredImage I put in.

So that’s all fine, but the MDX that I use to include React on myGatsby-powered blog has this YAML header:

---title: "MDXtestdate: "2020-02-29"featuredImage: "images/some_image.png"---

Changing this manually every time I want to blog about something getspretty old pretty quickly. So I use writeMDX, which will convert theformer to the latter. It also creates a proper MDX document that followspandoc’smarkdownspec. So a full RMarkdown might be this (ignore the# at the codechunks, just for formatting the README correctly):

---title: "MDXtest"author: "Robert McDonnell"date: "2/29/2020"output: html_documentfeaturedImage: "image/png.png"---#```{r setup, include=FALSE}knitr::opts_chunk$set(echo = TRUE)#```## writeMDX testThis is a test document for writeMDX. It has **bold**, *italic*  - lists   - sublists- and so onIt also has equations $y_{ij} = \alpha_j * beta_i$$$y_{ij} = \alpha_j * beta_i$$And it has code. For R:#```{r}x <- 5print(x)print(head(mtcars))#```And Python: #```{python}x = 3print(x)#```

And the MDX resulting from writeMDX will be:

---title: "MDXtest"date: '2020-02-29'featuredImage: "image/png.png"---writeMDX test-------------This is a test document for writeMDX. It has **bold**, *italic*-   lists    -   sublists-   and so onIt also has equations $y_{ij} = \alpha_j * beta_i$$$y_{ij} = \alpha_j * beta_i$$And it has code. For R:#``` {.r}x <- 5print(x)#```    ## [1] 5#``` {.r}print(head(mtcars))#```    ##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb    ## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4    ## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4    ## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1    ## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1    ## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2    ## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1And Python:#``` {.python}x = 3print(x)#```    ## 3

It’s not perfect, as you can see. The indentations could be removed,emojis work differently, and equations need a different set up. Theseare on myto-dolist; they may ormay not get done. If you’d like to make a PR for any of these, feelfree.

Why?? 😕

I loveReact, and I just rebuilt mywebsite usinggatsby.js, so now I want all the ease andpower of MDX. The only missing piece of the puzzle was doing some stuffin R, and then writing it out to an.mdx file that I can use to add inall the other stuff I want, like D3 graphs. R + React + Markdown =:purple_heart:

No CRAN? 😢

This won’t go on CRAN, since it’s mainlyrmarkdownpackage functions with an added format,which you can do yourselfquiteeasily.

About

writes RMarkdown (.Rmd) files to MDX (.mdx) format. Used for R ➡️ RMarkdown ➡️ Markdown ➡️ MDX ➡️ JS ➡️ Gatsby blog

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp