Change .Rmd file to .md file - r

How do I change an .Rmd file to an .md file, that I can then push to GitHub? I have knit to HTML
Is it possible to do this by something as simple as changing the file extension to ".md" and doing a save as? Any insight into what the differences are amongst these types of files would be so helpful!
Also, how different should an .Rmd and .md file look when opened?
Thank you!

You can add keep_md to your YAML header.
---
output:
html_document:
keep_md: true
---
Just be aware you will need to also push any related assets to Github as well as the .md file

You can use
knitr::knit("my_file.Rmd")
which should output my_file.md (a Markdown file with included code chunks) and generate figures (in a figs/ directory, I think, not sure).

Related

Unable to put references from bibtex files and csl files in Rmarkdown

I am trying to put the references as bib tex with b-9.bib and with some styling with .csl files. Both the Rmarkdown and the aforementioned files are present in the same working directory. But I am encountering this error when trying to knit to PDF.
YAML Header
---
title: "Swarm Intelligence"
output: html_document
bibliography: b-9.bib
csl: ieee.csl
---
Not sure if it is because of the hyphenated naming or path issue. I even tried giving the absolute path to the header path but still the issue. or am I missing some extra code chunk or so?
Ensure all your files have the same working directory. Also, try using "word_document" as the output format. I am not sure how your csl formatting would apply to a html document.

Rendering multiple Rmd files in the same directory to individual pdfs (R, bookdown)

I have several Rmarkdown (Rmd) files in the same directory, and want to render them into individual pdf files using bookdown::render_book. I normally use knitr::knit for that, but would like to take advantage of the cross-referencing in bookdown. But I would still like to have one Rmd file for each pdf file, and have them live independently in the same directory.
According to section 12.4 of the bookdown book I can use output: bookdown::pdf_document2 in the yaml header to generate a single pdf from an Rmd file. However, bookdown::render_book always combines all Rmd files that it finds in the directory, which is not what I want.
Is there an option in the yaml header or in the bookdown::render_book function where I can tell it to ignore all other Rmd files in the directory?
I know there is an option rmd_files I can specify in the file _bookdown.yaml but I don't know how this would work with multiple Rmd files, and I would also like to avoid having to maintain a separate yml file.

Set R bookdown input directory

I'd like to use bookdown to parse a series of .Rmd file into a book. If I have my .Rmd in the same directory as the main index.Rmd file then everything works fine and dandy. However, the .Rmd files are autogenerated from another source and I'd like to keep the input files in a subdirectory. Is it possible to do that?
I can include the file names in _bookdown.yml but I'd prefer not having to update that file every time a new .Rmd file is added.
The current version of _bookdown.yml looks like this
new_session: yes
rmd_files:
html: ["input/index.Rmd", "input/01-file.Rmd"]
latex: ["input/index.Rmd", "input/01-file.Rmd"]
I can move the files in a script but was hoping it was possible through bookdown itself.
In the development version of bookdown you can now provide a list of subdirectories to be search recursively.
For example to have it search dir1/ and dir2/ (and their subdirectories) you can specify rmd_subdir: ["dir1/", "dir2/"] in the _bookdown.yml.

Remove bookmarks in PDF created by RMarkdown

When I knit a PDF using RMarkdown, it automatically creates bookmarks in the PDF file from any headers I use.
For example a "bookmark" in the PDF is created when I do:
this is a header 2
Is there any way to prevent this from happening?
Thanks.
Looks like you have to modify the latex template.
https://github.com/rstudio/rmarkdown/blob/master/inst/rmd/latex/default.tex#L105
Set bookmarks=false at that line above. Then save as mytemplate.tex file to your working directory, and use this option in your front matter:
output:
pdf_document:
template: mytemplate.tex

Compile R Script to markdown

Using RStudio's "Compile Notebook to html" feature, I noticed that a temporary .md file was created in the process, but deleted automatically. At one point I was lucky enough to see its content, and it is exactly what I need: the code chunks alternate with output chunks, all perfectly formatted.
So my question is: how do I generate such an .md file directly form an R script?
You could also run knitr::spin() directly from the R console.
If you run "Knit to HTML", a markdown file is temporarily created and deleted. To keep the markdown file, add the following to the YAML code at the top of the RMD file.
---
output:
html_document:
keep_md: true
---
Here is a helpful reference: https://bookdown.org/yihui/rmarkdown/html-document.html#keeping-markdown

Resources