# 用 markdown 的逻辑写 R 脚本注释

in #cn2 years ago (edited)

## 九阳真经

--- 《学 R》第一章 “初见”

## .R 变成 .Rmd

.R .Rmd
"`#` + 空格" 开头的注释行 保留不变，成为章节标题
"`#` + 非空格字符"开头的注释行 去掉开头的`#`，成为正文文字

``````# Calculation --------
#This is a chapter about calculation.
## Assign x --------
#Assign x some values.
x <- 1:6
## Assign y --------
#Assign y some values.
y <- 11:16
# Plot --------
plot(x, y)
``````

``````# Calculation
This is a chapter about calculation.
## Assign x
Assign x some values.
​```{r}
x <- 1:6
​```
## Assign y
Assign y some values.
​```{r}
y <- 11:16
​```
# Plot
​```{r}
plot(x, y)
​```
``````

## .Rmd 变成 .R

``````#' # Calculation
#' This is a chapter about calculation.
#' ## Assign x
#' Assign x some values.
## ------------------------------------------------------------------------
x <- 1:6
#' ## Assign y
#' Assign y some values.
------------------------------------------------------------------------
y <- 11:16
#' # Plot
------------------------------------------------------------------------
plot(x, y)

.Rmd
.R

章节标题（"# + 空格" 开头）
后面添加 --------，在 RStudio 里以大纲视图展示

正文
开头加个"#"，成为注释行

代码块
去掉前后的三个反引号，成为代码行

Posted from my blog with SteemPress : http://dapengde.com/archives/19797``````
Sort:

#### Hi @dapeng!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 4.160 which ranks you at #3048 across all Steem accounts.
Your rank has improved 4 places in the last three days (old rank 3052).

In our last Algorithmic Curation Round, consisting of 210 contributions, your post is ranked at #108.

##### Evaluation of your UA score:
• Some people are already following you, keep going!