library(dplyr)
%>%
mtcars select(mpg, am ,vs) %>%
group_by(vs) %>%
summarise(mean(mpg))
Hide Comments from the Code Chunk in Rendered Document
View the source code of this document to compare with rendered version, by clicking
</> Code
on top-right corner.
To write a comment that will be hidden from the code chunk in rendered document, you need to use comment-directives. And the syntax of the comment directive depends on the language of the code chunk and therefore, should start with the character(s) that is used to do inline commenting in that programming language.
So for python, R and Julia, it should start with hash or pound symbol #
. For javascript or ojs or dot chunk, it should start with //
, for mermaid graph chunk it should start with %%
. It is because, after all, they should be valid comment line when the document parses.
After deciding on the syntax of comment-directives, enlist them with or under the comment-directive
yaml option. Then hide-comment
filter will remove the lines from code chunk that initiates with the enlisted directives.
This demo uses
#>
comment-directive for R and Julia code chunk.#?
comment-directive for python code chunk.//>
for ojs and dot code chunk%%>
for mermaid code chunk
R code chunk
Python code chunk
import matplotlib.pyplot as plt
1,23,2,4])
plt.plot([ plt.show()
Julia code chunk
using Plots
plot(sin, x->sin(2x), 0, 2π, leg=false, fill=(0,:lavender))
ojs code chunk
= Inputs.range(
viewof bill_length_min 32, 50],
[value: 35, step: 1, label: "Bill length (min):"}
{
)= Inputs.checkbox(
viewof islands "Torgersen", "Biscoe", "Dream"],
[value: ["Torgersen", "Biscoe"],
{ label: "Islands:"
} )
dot code chunk
graph G {
layout=neato
run -- intr;
intr -- runbl;
runbl -- run;
run -- kernel;
kernel -- zombie;
kernel -- sleep;
kernel -- runmem;
sleep -- swap;
swap -- runswap;
runswap -- new;
runswap -- runmem;
new -- runmem;
sleep -- runmem;
}
Mermaid code chunk
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts <br/>prevail!
John-->>Alice: Great!
John->>Bob: How about you? Bob-->>John: Jolly good!