FAQ: How to make your code look nice? Markdown Formatting

#1

Jump to Contents


Code Chunks

You type in community:

``` r
 #> A code chunk   
 library(foo)
```

You get:

    #> A code chunk   
    library(foo)
  • This is easier to read.
  • It also creates a clear chunk of code for others can copy and paste into their own R environment.

Inline Code

Type this:

I really wanted you to see `this_code_here`

See this:

I really wanted you to see this_code_here


Quote Snippets

If you highlight the content and click quote it will automatically populate the reply with the formatted code:

[quote="stephhazlitt, post:5, topic:6246, full:true"]
How do you insert a quote from the thread above (or elsewhere) that appears as a nicely formatted indented box in a reply?
[/quote]

You can also select text and click the quote button (highlighted below):

Using > also works:

This is a quote.

from ⇩

> This is a quote.

Hide/Show Folding Spoilers

Example text of what's shown - click to see what's hidden

Example spoiler text

[details = Example text of what's shown - click to see what's hidden]
Example spoiler text
[/details]

Pixelate Spoiler Hider

There is and images below that will be pixelated until you click on it.

[spoiler]
```
print("Joe Cheng is photogenic")

```
![image|256x250](upload://2ZcnTcOclyi2ErordryDHkhojWL.jpg)
[/spoiler]

Will appear as:

print("Joe Cheng is photogenic")


More Markdown Formatting Tips

For more markdown formatting options - including bold, italics, tables, etc. http://commonmark.org/help/
image


6 Likes

Add a Zoom on my plot
Can I put the result of read.files in a list and iterate through the list to match specific files
FAQ: What's a reproducible example (`reprex`) and how do I do one?
Connecting To A SQL Server
Sparklyr 's error
Help with function convert.inp in RMark
Displaying information on click in timevis.r
Track down error in R
Using www folder: Save and display pdf
Problem with Histogram
Ggplot adding points in large dataset, looks terrible
Cannot export a raster image after using the random forest classification
Error: cannot find function trim
Checking is.null in a case_when statement
How to customise colours to specific things
How to average/mean variables in R based on the level of another variable (and save this as a new variable)?
Problem in 'matplot' function
How to save SAS data into RData format
Ggplot troubleshoot: Error: Aesthetics must be either length 1 or the same as the data (24): x, y, fill
Create Volcano Plot
Error in file.choose() file choice cancelled
Error Preventing Knitting
Error in gzfile(path.expand(tarfile), "rb") : cannot open the connection In addition: Warning message: In gzfile(path.expand(tarfile), "rb") : cannot open compressed file 'NA', probable reason 'Permission denied'
Curl error 18 occurred
Multi-column-type Summarise
Error during deploy shiny app
Graph with errobar using percentile function
Suddelny, base solve function does not work on RStudio
Problem with source_python using pulp in Windows
Maptile fetched in RStudio Desktop but not RStudio Server
How to give admininstrative rights while running R script from terminal in Linux?
If/Else logic for fixing ZipCodes
Document term matrix in XGBoost classifier
Create plots using multpile dataframes
How to Ignore one of the factors in a Column
How to upgrade a package when using packrat
Error sourcing while creating Shiny app
R : dynamic plot value and x axis value for line chart
How to create a legend for ggplot
System call within R shiny
Not able to get an image into word/pdf from URL in RMarkdown
Shiny app r Programming
How to create a legend for ggplot
Efficient way to get column names.
I used clean data according a column number range isn't work correct.
Changing Base R code to dplyr/sparklyr
Package ‘dplyr’ is not available (for R version 3.4.3)
Shiny dashboard
Data frame not inserted the right value.
How to remove for
Error reading file
cut plots in the plot window
Making a bar plot
web scrapping data from webpage and save in data frame
Ggplot legend error
Text concatenation
outside save from loop
Using a pipe to sequentially filter data - receiving error
Fibbonacci series and Golden Ratio
Linear Mixed Model
Need help with strange pop-ups
Linear regression line looks wrong
Chapter starts with 0.1 (not 1.0) in pdf_book format
R Studio crashes when connecting to Spark with sparklyr
Error when trying to use corrplot
Problems with loading ggplot2
Get google place details for multiple place ids
How I can convert symbols to color code in this shiny code
What did my colleague do to prepare the data for an ICC?
Doubt with loops
Fatal Error when running Keras/Tensorflow with GPU
Plot multiple line graph over time
“edit” and “read.table” on R for Mac
Show matched and unmatched results from vector in data table
Improve the speed
unlisted #3
0 Likes

listed #4
0 Likes

#5

How do you insert a quote from the thread above (or elsewhere) that appears as a nicely formatted indented box in a reply?

1 Like

#6

If you highlight the content and click quote it will automatically populate the reply with the formatted code:

[quote="stephhazlitt, post:5, topic:6246, full:true"]
How do you insert a quote from the thread above (or elsewhere) that appears as a nicely formatted indented box in a reply?
[/quote]

You can also select text and click the quote button (highlighted below):

Using > also works:

This is a quote.

from ⇩

> This is a quote.
3 Likes

split this topic #8

2 posts were split to a new topic: How to make markdown tables?

0 Likes

#9

R Markdown Source

Use four backticks and the "markdown" syntax hint to surround the source of R Markdown documents:

Type this:

````markdown
---
title: "It's full of cars!"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.

```{r cars}
summary(cars)
```
````

See this:

---
title: "It's full of cars!"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. 

```{r cars}
summary(cars)
```
9 Likes

Floating table of contents and plots produce extra whitespace at bottom
Unloading package in one block does not affect the next block
R markdown html code_folding problem
Remove values Based on a criteria and re-run average, sd and sem
Sometimes when caching chunks in markdown variables can't be referenced in next chunk, why?