学习 knitr和 rmarkdown的一些语法
20 Aug 2016
Go backknitr::opts_chunk$set(echo = TRUE,prompt = T)
#global setting e.g. if you want to set prompt = T for defalut,than you can set in here
#there is an arguement here *include* if you set T, than you can see this command,so as F
* If you use separator you should print * * * ,but remember to skip lines up and down
you need to know is that there are two type of the grammer in for the title:the Setext-like and atx-like
I just need to know the latter one atx-like.The maximum is six #(pounds)
#This is the title use one pound
##This is the title use two pounds
###This is the title use three pounds
####This is the title use four pounds
Use > to do so. example >my first reference
my first reference
out1
if your content is very long, you don’t need to change to a new line manually
you can use the follow way if your links are few. If large you can search the Internet! e.g. [baidu]\((https://www.baidu.com/\))
e.g.
![picName](/path/to/img.jpg)
use warnings
e.g. ``` perl \(a=1;\)b=$a+1 ```
$a=1;
$b=$a+1;
following is the table code, it as widly aknowledged that use of table is annoyed
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
:--- alignment of left
---: aligement of right
:---: middle
Tables | Are | Cool |
---|---|---|
col 3 is | right-aligned | $1600 |
col 2 is | centered | $12 |
zebra stripes | are neat | $1 |
Hi report! #warn: Don’t use Chinese!
the following page is writted by the way of code and it’s effect
\```{r}
a<-1
a+1
\```
> a<-1
> a+1
## [1] 2
```{r label} You can also plus a label and the label will be the index at the lower left quarter
a<-1
a+1
```
How about we don’t use the curly braces, following is the result.
a<-1
a+1
As you can see ,R won’t execute the code, it just highlight them.
So till now I really want to know if we use perl,I mean instead perl with r in the curly braces
Let me try
\```perl
$a=1;
$b=$a+1;
print "$b";
\```
and
\```{perl}
$a=1;
$b=$a+1;
print "$b";
\```
$a=1;
$b=$a+1;
print "$b";
> $a=1;
+ $b=$a+1;
+ print "$b";
## 2
Now we can see it works. Yeah good job!!
\```{r}
a =1:10
b =11:20
a #This way you can annotate the code!
\```
> a =1:10
> b =11:20
> a #This way you can annotate the code!
## [1] 1 2 3 4 5 6 7 8 9 10
\```{r arg1,echo=F} #defalut echo=T
a =1:10
b =11:20
a #This way you can annotate the code!
\```
## [1] 1 2 3 4 5 6 7 8 9 10
You can see the result is just the out put of the R code!!!
\```{r arg2,eval=F} #defalut eval=T
a =1:10
b =11:20
a #This way you can annotate the code!
\```
> a =1:10
> b =11:20
> a #eval=F
You can see the result is just the R code, same as the basic use!!!
And you can control which line of the code to execute use eval =c(the vector of the lines)
> a =1:10
> b =11:20
> a #eval=F,highlight=FALSE
> a =1:10
> b =11:20
> a #eval=F,highlight=TRUE
> a =1:10
> b =11:20
> a #prompt=T
## [1] 1 2 3 4 5 6 7 8 9 10
please see the e.g.
> for (i in 1:10
+ )
+ {
+ print(i)
+ }
> #don't use tidy=T
> for (i in 1:10) {
+ print(i)
+ }
> # don't use tidy=T
So in order to show a better look, your can choose to select the arguement prompt, let it be TRUE
\```{r}
plot(1:10)
\```
> plot(1:10) #defult arguements
\```{r,fig.cap="the fig test",fig.width=3,fig.height=3}
plot(1:10)
fig.cap="the fig test";fig.width=3,fig.height=3
\```
> plot(1:10)
the fig test
> #fig.cap="the fig test";fig.width=3,fig.height=3
Other usage need you to development!!!!!!!!!!!
> fit = lm(dist ~ speed, data = cars)
> b = coef(fit) # coefficients
> summary(fit)
##
## Call:
## lm(formula = dist ~ speed, data = cars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.069 -9.525 -2.272 9.215 43.201
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -17.5791 6.7584 -2.601 0.0123 *
## speed 3.9324 0.4155 9.464 1.49e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 15.38 on 48 degrees of freedom
## Multiple R-squared: 0.6511, Adjusted R-squared: 0.6438
## F-statistic: 89.57 on 1 and 48 DF, p-value: 1.49e-12
The code will be highlighted in all output formats.
> par(mfrow = c(2, 2), pch = 20, mar = c(4, 4, 2, .1), bg = 'white')
> plot(fit)
Regression diagnostics
Our regression equation is \(Y=-17.5790949+3.9324088x\), and the model is:
\[ Y = \beta_0 + \beta_1 x + \epsilon\]
We have some examples.
0.3 + 0.4 - 0.7
. Zero. Easy.0.3 - 0.7 + 0.4
. Still zero?People are often surprised by (2).
A table here.
Right | Left | Center | Default |
---|---|---|---|
12 | 12 | 12 | 12 |
123 | 123 | 123 | 123 |
1 | 1 | 1 | 1 |
We compile the R Markdown file to Markdown through knitr [@xie2013] in R [@R-base]. For more about @xie2013, see http://yihui.name/knitr.