In this great stackoverflow post I read about making comments in Markdown. I would like to use this to visually structure my jmd document:
---
title: My Title
output: pdf_document
---
[\\]: # (###########################################)
[\\]: # (Title Page)
[\\]: # (###########################################)
Some text here.
I can weave this document and get the correct output, but I get warnings
[WARNING] Duplicate link reference '[\\]' at line 8 column 1
[WARNING] Duplicate link reference '[\\]' at line 9 column 1
which I would prefer to avoid.
How can I comment in Julia Markdown without getting warnings?
You can do this
<!-- ###################################################### -->
<!-- ####### Title Page -->
<!-- ###################################################### -->
Honestly, I liked the option from the question better, because it is technically a link and therefore in VSCode displayed much better, but you can't have everything, I guess.
Related
I am trying to comment out a section of code in my RMarkdown. I know that I can use the <!-- --> syntax to add comments, but these comments still appear in the rendered HTML (although hidden). Is there a way to create real comments that are ignored during rendering and don't appear in the exported document source code?
You can wrap everything in ~~~{=comment} ... ~~~ to get it ignored:
Normal text
~~~{=comment}
this will be ignored
This, too!
~~~
No longer in a comment.
You could specify with echo to code lines to show in your output like this:
---
date: "2022-12-13"
output: html_document
---
```{r echo=2:4}
# This comment should not be shown
rnorm(3)
# But keep this comment in output html
```
Output:
As you can see it doesn't show the first comment.
I'm trying to generate a quarto document in pdf (and word later). I'm meeting an issue with the mermaid graph.
Please find bellow a sample .qmd file to illustrate the issue.
So first it's supposed to support the {mermaid} tag but when i do that, I can't "run" the cell in rstudio, but also my document doesn't actually generated and the "background jobs" in rstudio gets stuck on "output file: testmermaid.knit.md"
So I use DiagrammeR::mermaid to encapsulate this, then the document is indeed generated but the size is too small and if I resize the figure generated then it becomes all blurry.
I made many attempts but none of them worked so if someone would have a simple solution where the diagram would go Xcm from the left to Ycm to the right, and be generated correctly in pdf and word?
EDIT:
After #Shafee's comment, I've noticed I didn't have the quarto package installed, I have now installed the latest R package quarto 1.0.36 and reinstalled RStudio (2022.07.1 build 554) for the sake of it, but the problem is unchanged.
I've also noticed my personal computer (same version of RStudio and quarto) doesn't have these issues (still can't run a mermaid chunk in Rstudio IDE though)
EDIT2:
after a full reinstall on the local hard drive (instead of windows network drive) I get this:
output file: testmermaid.knit.md
ERROR: Couldn't find open server
my version is now:
quarto::quarto_version()
1 ‘1.1.189’
---
title: "TestMermaid"
format: pdf
---
```{r libimport}
library(quarto)
library(DiagrammeR)
knitr::opts_chunk$set(echo = F)
```
## Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
Attempt #1
```{mermaid attempt1}
flowchart LR
A[Hard edge] --> B(Round edge)
B --> C{Decision}
C --> D[Result one]
C --> E[Result two]
```
Attempt #2
```{r attempt2}
mermaid("
sequenceDiagram
participant ParticipantA
participant ParticipantB
participant ParticipantC
ParticipantA->>ParticipantB: I want something
ParticipantB->>ParticipantC: he want something
ParticipantC->>ParticipantB: here is something
ParticipantB->>ParticipantA: he got something for you
", height = '100%', width = '100%')
```
Your code executes as intended once the library(quarto) call is removed from line 7.
As per the documentation for Quarto figures. The size can be increase through the use of chunk options.
```{mermaid attempt1}
%%| fig-width: 6.5
%%| fig-cap: Fig 1. Test figure
flowchart LR
A[Hard edge] --> B(Round edge)
B --> C{Decision}
C --> D[Result one]
C --> E[Result two]
```
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:
I am creating a presentation with Rstudio using knitr and I want to use the types of the slides to generate a table of contents slide in the beginning. So if I have the following code:
Some fun lecture
========================================================
author: some guy
date: in the future
Table of content slide
========================================================
Here I want the table of content based on the following slide types
Some stuff 1
========================================================
type:section
Some very important stuff
More detail on stuff 1
========================================================
type:subsection
Did not get enough of stuff 1!? Here is more :D
Stuff 2
========================================================
type:section
There are other kinds of stuff?
Prompt slide
========================================================
type:prompt
Do not display prompt or alert types in TOC
So basically I want a table of content slide after the title slide looking something like:
Some stuff 1
More detail on stuff 1
Stuff 2
Is this available by default or do I need some extra CSS style in the beginning to handle this?
To generate a table of contents, include a document header with the option "toc:true" at the beginning of the document. Level 1 headings are indicated by #, level 2 headings by ##, and so on. Below is an example . The "prompt" option is only relevant for R code chunks. R code chunks are not listed in the table of contents.
This will, however, only produce a html document. If you want a Latex-like presentation with individual slides, you can replace html_document with beamer_presentation. In the beamer presentation, only level 1 headings are listed in the table of contents.
---
title: "Sample Document"
author: "Author"
output:
html_document:
toc: true
---
# Some stuff 1
Some very important stuff
## More detail on stuff 1
Did not get enough of stuff 1!? Here is more :D
# Stuff 2
There are other kinds of stuff?
```{r, prompt=TRUE}
summary(iris[, "Sepal.Length"])
```
For more info on Beamer presentations in Rmarkdown, see http://rmarkdown.rstudio.com/beamer_presentation_format.html. A similar question has been answered here.
This is my first questions on StackOverflow, so please let me know if I'm doing anything wrong.
I'm using R to generate a lot of very large PDF documents. My data is about 580,000 observations, and breaks down in to 32 categories with each category containing 70 answers to between 20 and 300 questions. Currently I use two for loops (I try to avoid for loops, but for creating these pdfs it was the only way that worked). The first goes through and creates a pdf for the category with a title page, then the second adds a page for each graph showing the results of that question. I'm using ggplot2 & the "pdf" function.
The script works great, creating 32 pdfs (one for each category) with a custom title page and pages for all the questions in that category. I would like to add a Table of Contents after the title page. I know how to add a page with labels and page numbers, but I need one that links to each question.
I've searched this site and Google, but haven't found any way to do this in R. This question: Adding a table of contents to PDF with R plots talks about using RPython. I've also come across sources mentioning "hyperref", LaTex, Pandoc, and Knitr. I know how to use Kintr in an Rmarkdown doc, but that doesn't work for what I'm trying to do. I'm not really sure how to work with any of the others, so solutions with using them went over my head.
Is there not a way to work with creating a Table of Contents or just hyperlinks to PDF pages inside R, without going to those other languages?
Have you tried just clicking on the section names in the table of contents? By default, these seem to be hyperlinked, although there isn't any colouration that hints at it.
To help you see what might be happening, add / change your YAML header to add the following:
output:
pdf_document:
keep_tex: true
toc: true
toc_depth: 3
That will get the intermediate .tex file kept. If you open that up after knitting, you should already see references to hyperref in it.
I then find my table of contents being defined as:
{
\hypersetup{linkcolor=black}
\setcounter{tocdepth}{3}
\tableofcontents
}
which produces a hyperlinked TOC, but with "black" hyperlinks!
If you want to change the colour and see them show up, you can open the tex file in RSudio and simply change the "black" to "blue" and have RStudio run "Compile PDF" and you should see them showing up.
If you want your page numbers hyperlinked rather than the description, add the following into your YAML:
header-includes:
- \hypersetup{linktocpage}
Share & Enjoy!
I just remembered I left this open and thought I'd go back and post how I ended up solving it, well sorta. Instead of an R script, I used a R Markdownfile to create a combined pdf, which included all sections with their subsequent questions as different levels. I was able to create a pdf for each section individually with a linked clickable Table of Contents including all of its questions(pages) and different header levels for title pages.
The key was pandoc.header, which allowed me to create the headers, which show in the TOC. I think neither the for loops, nor the ggplot, which was created for each page, is relevant. Here is an overview of the .rmd :
title:
author:
output:
pdf_document:
toc: true
```{r results = "asis", message=FALSE, warning=FALSE, echo=FALSE, fig.height = 11, fig.width = 8}
for(i in 1:length(categories){
pandoc.header(paste("Category ",category_num, ": ", category discription), level = 1)
category title page
for(i in 1:numberofquestions){
pandoc.header(paste("Question ",question_num, ": ", subtitle1), level = 2)
print(ggplot())
}}
```
The only inconvenient part is that each page must have a header to be linked to and I really didn't like the title pages having one, but it looks like I can manually edit that out with what dsz posted.