I have begun using Rmd to render Powerpoint presentations consistently, using the YAML tags and more importantly, a reference Powerpoint to ensure standardized / consistent formatting:
output: powerpoint_presentation: slide: reference_doc: "reference.pptx". When I want to share a PPT document as a reference for my peers / students however, I want to be able to have my slides available as a .pdf file.
I have had success using shell commands in R using LibreOffice's soffice command, however I am not always at a workstation with that available. Is there a portable solution / executable I can call, or additional Rmd tags for rendering a document with a .pptx reference document, but rendered as a .pdf file?
I believe you have to specifiy output: beamer_presentation in the header.
Take a look at this: https://rmarkdown.rstudio.com/formats.html
Related
I'm trying to embed a static image of a targets workflow in an rmarkdown document. I tried to do this by using tar_mermaid, defining a target that writes the workflow in mermaid format mm <- tar_mermaid(); writeLines(mm, "target_mermaid.js") but the help for tar_mermaid says
You can visualize the graph by copying
the text into a public online mermaid.js editor or a mermaid GitHub code chunk
I am looking for a programmatic way to either (1) embed the Javascript output in an (R)markdown file, or (2) render it (as SVG, PNG, whatever).
I thought as a shortcut that I could cut-and-paste into a markdown code chunk delimited by ```mermaid, or use cat(readLines("target_mermaid.js"), sep = "\n") in a chunk with results = "asis" but I guess that only works in Github markdown (I'm using Pandoc to render to HTML) ... ?
The visNetwork package has a visSave() function which can save to HTML (not quite what I wanted but better than what I've managed so far), and a visExport() function (which saves to PNG etc. but only by clicking in a web browser). Furthermore, targets wraps the visNetwork functions in a way that is (so far) hard for me to unravel (i.e., it doesn't return a visNetwork object, but automatically returns a widget ...)
For the time being I can go to https://mermaid.live, paste in the mermaid code, and export the PNG manually but I really want to do it programmatically (i.e. as part of my workflow, without manual steps involved).
I am not quite sure about the answer. But I have an idea. And I will delete if it is not adequate:
If you want execute mermaid code to get for example an html output then you could do this with quarto. I am not sure if this is possible with rmarkdown:
See https://quarto.org/docs/authoring/diagrams.htmlS
---
title: "Untitled"
format: html
editor: visual
---
## Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
## Running Code
```{mermaid}
flowchart LR
A[Hard edge] --> B(Round edge)
B --> C{Decision}
C --> D[Result one]
C --> E[Result two]
```
output:
#landau's suggestion to look here almost works, if I'm willing to use Quarto instead of Rmarkdown (GH Markdown is not an option). The cat() trick was the main thing I was missing. The .qmd file below gets most of the way there but has the following (cosmetic) issues:
I don't know how to suppress the tidyverse startup messages, because targets is running the visualization code in a separate R instance that the user has (AFAIK) little control of;
the default size of the graph is ugly.
Any further advice would be welcome ...
---
title: "targets/quarto/mermaid example"
---
```{r}
suppressPackageStartupMessages(library("tidyverse"))
library("targets")
```
```{r, results = "asis", echo = FALSE}
cat(c("```{mermaid}", tar_mermaid(), "```"), sep = "\n")
```
Beginning of document:
Zooming out:
All my codes developed in base R and I don't want to use RStudio, however I want to use rmarkdown feature in base R which is available in Rstudio.
I have downloaded rmarkdown package in base r, but not able to derive a code to publish my work
All the output of my codes written in R should be view able through web browser.
First make sure you're using .Rmd as your file extension. If not, rename it to a .Rmd extension. Make sure you have Pandoc installed on your OS.
Next, add the following to the top of the file:
---
title: "Your notebook title"
output: html_document
---
output: could take any value. You can pass in the value of ioslides_presentation for example if you want but it looks like html_document fits the criteria of what you want pretty well.
Once you have that, write your code in any editor (or the R console if you prefer). Use the code chunks and markdown text formatting as you normally would:
```{r}
plot(1:10)
```
In my base R Console, this is how mynotebook.Rmd looks like:
Finally, use the render() function from rmarkdown. You can either attach it and run render():
library(rmarkdown)
render("mynotebook.Rmd")
Or, run rmarkdown::render("mynotebook.Rmd").
Notice that the use of RStudio is not required at all since Pandoc is the document converter performing this task. For the so inclined, this is what its documentation has to say:
When you run render, R Markdown feeds the .Rmd file to knitr,
which executes all of the code chunks and creates a new markdown (.md)
document which includes the code and it's output.
The markdown file generated by knitr is then processed by pandoc
which is responsible for creating the finished format.
This may sound complicated, but R Markdown makes it extremely simple
by encapsulating all of the above processing into a single render
function.
I have been using .Rmarkdown files to create blog posts in R blogdown. The output of chunk of codes in .Rmarkdown documents are printed in the console and not in the document.
If instead I create a .rmd file, then previews are in window. RStudio Global options are set to show preview in window for RMarkdown documents.
Is this an expected behavior of .rmarkdown files?
Thanks
The differences between .Rmarkdown and .Rmd is explained here. The most relevant quote being:
In this book, we usually mean .Rmd files when we say “R Markdown documents,” which are compiled to .html by default. However, there is another type of R Markdown document with the filename extension .Rmarkdown. Such R Markdown documents are compiled to Markdown documents with the extension .markdown, which will be processed by Hugo instead of Pandoc.
More specific differences are explained in the book linked above.
I am working with markdonw v2, the rmarkdown package. Throughout the .Rmd file, I create links to websites or images
[Link1][pathLink1]
![Image1][pathImage1]
then, at the end of the document I give the references
[pathLink1]:http://website.com/linkes/Link1.md
![pathImage1]:./images_rmd/
There are other reports that talk about the same citation and use same images in different contexts. I would like to create a separate file containing all the links and path difinitions, so that I could simply source it at the end of each .Rmd file, like I would call in an R environment
source(/Rcode1.R)
Question: How do I "source" another file in .Rmd, so that the sourced code prints needed text strings into the .Rmd file?
This would offer some help with citations and scientific paper composition in HTML and PDF.
http://yihui.name/knitr/demo/child/
```{r child, child = '~/path/to/child.Rmd'}
```
and similarly for .Rnw files:
<<child, child = '~/path/to/child.Rnw'>>=
#
And a full example: https://github.com/yihui/knitr-examples/blob/master/087-child-example.Rnw
I have been saving some example R markdown html output to Word using pandoc. I actually only do this so I can add some page breaks for easier printing:
system("pandoc -s Exercise1.html -o Exercise1.docx")
Although the output is acceptable I was wondering if there is a way to keep the original syntax highlighting of the R chunks (just as they are in the original knit HTML document)?
Also, I seem to be loosing all images in the conversion process and have to stick them into Word by hand. Is that normal?
Using the rmarkdown package (baked into RStudio Version 0.98.682, the current preview release) it's very simple to convert Rmd to docx, and code highlighting is included in the docx file.
You just need to include this at the top of your markdown text:
---
title: "Untitled" # obviously you can change this
output: word_document # specifies docx output
---
However, it seems that page breaks are still not supported in this conversion.
Why not convert the markdown directly to Word format?
Anyway, Pandoc does not support syntax highlighting in Word: "Currently, the only output formats that uses this information are HTML and LaTeX."
About the images: the Word file would definitely include those if you'd convert the markdown to Word directly. I am not sure about the HTML source, but I suppose you might have a path issue.