Package: rmdawn
IntroductionThermdawnPython package allows you to (de)construct, convert, and renderR Markdown(Rmd) files inyour terminal (e.g.bash,zsh,fish, etc.) oryour favorite Python environment (e.g.PyCharmorVisual Studio Code).ThermdawnPython package consists of 6 shell commands and functions:rmdawn, which concatenates input files to generate an Rmd file.rmdusk, which extracts 1) a YAML file, 2) Python or R scripts and 3)Markdown(md) files from Rmd files.rmdtor, which converts Rmd files into R scripts usingknitr::purl.rtormd, which converts R scripts into Rmd files usingknitr::spin.render, which creates rendered versions of R scripts or Rmd files into HTML, PDF, Word, andother output file formats.catren, which combines the functionality ofrmdawnandrenderto generate an Rmd file from source files and then create an output file.Allrmdawnfunctions and commands, except forrmdawnandrmdusk, rely on therpy2Python library.
The command line interface relies on theclickPython library.For a related package that provides programmatic tools for working withJupyter
Notebooks,
check out theNbless Python package.Documentation and CodeThe documentation is hosted athttps://py4ds.github.io/rmdawn/.The code is hosted athttps://github.com/py4ds/rmdawn.Installationpipinstallrmdawnor clone therepo, e.g.git clonehttps://github.com/py4ds/rmdawnand install locally using setup.py (python setup.py install) orpip(pip install .).Creating an R markdown file with thermdawnshell commandrmdawnheader.ymlintro.mdscrape.pyplot.Rnotes.txt>example.RmdInstead of redirecting to a file (>), you can use the--out_fileor-oflag:rmdawnheader.ymlintro.mdscrape.pyplot.Rnotes.txt-oexample.RmdThe easiest way to handle large numbers of files is to use the*wildcard in the shell.rmdawnsource_file*-oexample.RmdExtract YAML, markdown, and code files from R markdown files with thermduskshell commandrmduskexample.RmdConvert between R markdown and R code files with thermdtorandrtormdshell commandsrmdtorexample.Rmdrtormdexample.RYou can also specify an new filename with--out_fileor-oflag.rmdtorexample.Rmd-onew.Rrtormdexample.R-onew.RmdRender R markdown and R code files with therendershell commandThe default output format is HTML.renderexample.Rmdrenderexample.RYou can specify output format with the--formator-fflag.renderexample.Rmd-fword_documentrenderexample.R-fword_documentIf you only specify output filename with the--out_fileor-oflag,renderwill try to infer the output format from the file extension.
This will not work for slides or R markdown notebooks.renderexample.Rmd-oexample.pdfrenderexample.R-oexample.pdfCreate an R markdown file from source files with thecatrenshell commandYou can pass--rmd_file(-r),--out_file(-o), and--format(-f) arguments tocatren.The default output format is HTML.catrenheader.ymlintro.mdscrape.pyplot.Rnotes.txt-rexample.RmdIf you only specify an output filename with the--out_fileor-oflag,catrenwill try to infer the R markdown file name and output format from the file extension.catrenheader.ymlintro.mdscrape.pyplot.Rnotes.txt-oexample.pdfIf you only specify an output format with the--formator-fflag or do not provide any optional arguments,catrenwill create a temporary file in a temporary location.catrenheader.ymlintro.mdscrape.pyplot.Rnotes.txt-fword_documentcatrenheader.ymlintro.mdscrape.pyplot.Rnotes.txtBasic usage: Python environmentfrompathlibimportPathfromrmdawnimportrmdawnfromrmdawnimportrmduskfromrmdawnimportrtormdfromrmdawnimportrmdtorfromrmdawnimportrenderfromrmdawnimportcatren# Create an R markdown file from source filesfile_list=["header.yml","intro.md","scrape.py","plot.R","notes.txt"]Path("example.Rmd").write_text(rmdawn(file_list))# Extract source files from an R markdown filermdusk("example.Rmd")# Convert R markdown files into R scriptsrmdtor("example.Rmd")# Convert R scripts into R markdown filesrtormd("example.R")# Generate output files from R scripts or R markdown filesrender("example.Rmd")# The default format is HTMLrender("example.R")# The default format is HTMLrender("example.Rmd",out_format="pdf_document")render("example.R",out_format="word_document")# Create an R markdown file from source files output files and render itfile_list=["header.yml","intro.md","scrape.py","plot.R","notes.txt"]catren(file_list,rmd_file="example.Rmd")# The default format is HTMLcatren(file_list,rmd_file="example.Rmd",out_format="pdf_document")catren(file_list,out_file="example.html")# Another alternative is to import the package and use it as a namespace.importrmdawnrmdawn.rmdawn(["header.yml","intro.md","scrape.py","plot.R","notes.txt"])rmdawn.rmdusk("example.Rmd")rmdawn.rtormd("example.R")rmdawn.rmdtor("example.Rmd")rmdawn.render("example.Rmd")# The default format is HTMLNext StepsCurrently,xaringanslides require a special format.Writeremark/demarkfunctions and commands to add/remove slide delimiters---before headers#.