convert rmarkdown text to markdown text by passing rmarkdown text as input rathen then passing rmarkdown file

rmarkdown::render(markdownFile, quiet = TRUE, output_file=mdFileName, md_document(variant = "markdown_github"))

above function from the rmarkdown package works fine.
it takes rmd file and md file as input, converts rmd file content to md content and writes to md file.

Is there any function in rmarkdown package that takes rmd text as input and returns md text as output.

Thanks

There is no function that do exactly like rmarkdown::render() that takes text. It operates on file with some YAML header. But that is easy enough to make a wrapper to write to text before converting with render()- did you try that ? Is something not working ?

Otherwise, Do you want to convert a full R Markdown document, or piece of it ?

  • knitr::knit()take text input and will convert to markdown by evaluating R code (but without pandoc conversion from Pandoc's Markdown to GFM)
  • pandoc::pandoc_convert() uses Pandoc only and take text input too. No R evaluation though. Useful if you need bare pandoc. Using to = "gfm" will convert to GFM content.
1 Like

Thanks for your reply.
I am very much new to R.
Kindly confirm, if I understood the suggested approach :-

Step 1. knitr::knit() takes rmd text input and returns text output and evaluates the R code

Step 2. text returned in step 1 then be passed to pandoc::pandoc_convert() which will return the GFM text.

Yes this would work. This is basically what R Markdown is doing for you, so easiest would be

  1. Create temporary folder infrastructure
  2. Write your text content into a temporary Rmd file
  3. Use rmarkdown::render() with github_document() format
  4. Move your file output to the right place or read from your file output
  5. Remove the temp folder infra

I was mentioning knitr::knit() or pandoc::pandoc_convert() if you needed either to

  • Write a GFM doc with R code
  • Just convert text to GFM (without any R code).

Anyhow, writing to file and using R Markdown is the easiest

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.