Khi sử dụng tiếng Việt, tên bảng và tên hình sẽ hiển thị dưới dạng tiếng Việt, vì vậy không nên sử dụng lẫn tiếng Anh và tiếng Việt trong cùng một văn bản. Đặc biệt khi knit sang pdf vì nếu không bật package vntex thì sẽ không knit được văn bản có tiếng Việt sang pdf trong khi vẫn knit được sang word/html.
Khi muốn knit sang word thì nên dùng temporary citation của Endnote sau đó sẽ sử dụng update citation trong endnote. Khi muốn knit sang pdf thì có thể dùng citation của BibTex. Chú ý dùng BibTex cũng có thể knit sang word nhưng không có hyperlink. Chú ý không mix giữa 2 kiểu citation đề cập ở trên.
Để sử dụng tiếng Việt cần chọn code UTF-8. Khi mở văn bản nhớ chuyển không khi gõ tiếng Việt bằng ISO sau đó chuyển sang UTF-8 sẽ bị lỗi font.
Không nên sử dụng $...$ để chèn text dạng toán học vào văn bản vì sẽ dẫn đến lỗi khi knit (1) hiển thị sai (2) không knit được, đặc biệt là khi knit sang pdf. Tuy nhiên, vẫn sử dụng để chèn công thức vào text. Ví dụ: \(\left(\frac{a}{b}\right)\)
Có thể dùng một văn bản được knit từ Rmarkdown để làm template. Ở đây là Template 1.docx.
Ví dụ về trích dẫn dùng BibTex. Mutel and Hellweg (2009), and Clarens et al. (2010).
Khi gõ bằng tiếng Việt có lỗi trong vị trí chuột, khó sử dụng. Nguyên nhân có thể là do khi gõ bằng tiếng Việt các ký tự đặc biệt được tính nhiều vị trí hơn. Sẽ không bị lỗi khi gõ bằng Unicode dựng sẵn.
Sử dụng ‘...’ để đánh text có định dạng giống định dạng cho code. Có thể sử dụng 12’ để tính nhanh giá trị của equation. Ví dụ 4 sẽ cho kết quả là 4. ‘$ a + b = c $’.
Tạo hết các caption cho Table và Figure ở một section đầu văn bản, có thể sử dụng results=hide để ẩn các giá trị trung gian. Khi thay đổi vị trí các caption ở section này thì caption number sẽ tự động thay đổi. Cũng có thể sử dụng các caption này làm cho cross-reference.
Để thay đổi style trong YAML tham khảo thêm trong link sau: [http://rmarkdown.rstudio.com/html_document_format.html#advanced_customization]
Để đánh được caption có bao gồm các ký hiệu toán học (1) sau khi tạo Figure and Table captions như ở bước 9, tạo thêm các text chứa figure and table caption riêng.
See in the source code.
It is easy to use temporary citation of Endnote to incoporate the citation into Rmarkdown document. When we knit it into docx file, we can use the update bibliography function in Endnote to insert citation and bibliography into the final document {Luong, 2014 #678}. Here we use the first author’s name separated with the year by comma along with the record number of the reference preceeding by #. Each reference has only the unique record number.
When citing several documents, all citations as above are embraced in a curly bracket, and separated by semi-colon {Luong, 2014 #678; Ulanowicz, 2004 #205}.
In case we want to eliminate the author name because the author name (Ulanowicz) is already present in the text, we just left the author name from the curly bracket {, 2004 #205}.
We can also include the prefix and suffix into the citation. The prefix phrase must always be following by a back slash, a suffix simply follows the record number, no special marker is necessary (e.g. Luong, 2014 #678 for example). Also note to put the spaces in the appropriate spots so that the formatted citation looks correct.
First we have to turn on fig_caption in YAML header, which is turn off by default.
This is to write the R-code
variable_t <- 3*4 # create a new variableWe can refer to the variable_t’s value by writing 12. Note the use of backticks instead of quotation marks. Backticks can also be used to write code-like text: here is some code or even do a quick calculation 18.
Here is a code chunk that won’t be printed in the output:
Below is a chunk that will make a plot of the dataset iris. we can refer to it in text as normal: see Figure .
#If we knit to pdf we does not need to specify the number of Figure and we can use cross-ref. Cross-ref does not work for knit to word and html.
plot(iris)This is the figure of species abundance.
The above approach is not a good way to proceed with the numerous number of Figures or table. We should you the following approch. This allows automatic update of Figure number when we change it place… (do this when knit to word/html)
See more in [http://www.r-bloggers.com/figure-and-table-captions-in-markdown/] The author propose a solution for reference figures and tables.
## not see
require(FSAdata)
data(RuffeSLRH92)
require(FSA)
require(knitr)
require(captioner)Separate Captioner objects must be initialized for handing figures and tables.
figs <- captioner(prefix="Figure")
tbls <- captioner(prefix="Table")These functions can be used to create an object that holds a tag, captions, and number for figures or tables, respectively. Initially these functions are called with two arguments - the figure or table tag and the figure or table caption.
It is preferable to cate all tags and captions in one chunk (and use results='hide' to hide the immediate display information)
figs(name="LenFreq1", "Length frequency of Ruffe captured in 1992.") # put the name and tag for the caption. The names can be used to refer to the Figures.
figs(name="WtFreq1", "Weight frequency of Ruffe captured in 1992.")
tbls(name="SumLW1", "Summary Statistics of the length and weight of Ruffe capture in 1992")Chú ý tên các figure ở đây phải đánh chính xác khi sử dụng ở dưới nếu không thứ tự của Figure sẽ bị thay đổi
Summary Statistics \(x_i\) \(\frac{x^2}{2x}\) of the length and weight of Ruffe capture in 1992 This Function can be used to retrieve the function name with a number, the figure number with a prefix, or the figure number.
# This chunk is used to check the output of figs.
figs("LenFreq1")## [1] "Figure 1: Length frequency of Ruffe captured in 1992."
figs("lenFreq1", display="cite")## [1] "Figure 3"
figs("lenFreq1", display="num")## [1] "3"
Now we can used the figs function to add caption to a figure or use as a cross reference. For example: As can be seen from Figure 1, the results are more or less normally distributed.
Để đánh caption có chứa công thức toán học, thì caption phải được đánh riêng. Chỉ sử dụng Figure cite để lấy số thứ tự của Figure. Figure 1.Summary Statistics \(x_i\) \(\frac{x^2}{2x}\) of the length and weight of Ruffe capture in 1992
Note that when we changes the order of figs in the chunk code, the order of figs in the text also changed
Rmarkdown offers us some posibility for adding tables into the document.
require(pander)## Loading required package: pander
x <- 1:5
y <- 2*x + rnorm(5)
model <- lm(y~x)
summary(model)##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## 1 2 3 4 5
## 0.1907 -1.0338 0.6695 0.9996 -0.8261
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.2770 1.0891 0.254 0.81569
## x 1.9243 0.3284 5.860 0.00991 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.038 on 3 degrees of freedom
## Multiple R-squared: 0.9197, Adjusted R-squared: 0.8929
## F-statistic: 34.34 on 1 and 3 DF, p-value: 0.00991
X <- data.frame(y, x)| Estimate | Std. Error | t value | Pr(>|t|) | |
|---|---|---|---|---|
| x | 1.92 | 0.328 | 5.86 | 0.00991 |
| (Intercept) | 0.277 | 1.09 | 0.254 | 0.816 |
kable(summary(model)$coef, digits = 2)| Estimate | Std. Error | t value | Pr(>|t|) | |
|---|---|---|---|---|
| (Intercept) | 0.28 | 1.09 | 0.25 | 0.82 |
| x | 1.92 | 0.33 | 5.86 | 0.01 |
library(xtable)
tab <- xtable(summary(model)$coef, digits=c(0, 2, 2, 1, 2))
print(tab, type="html") # This is only work when we knit to html.The results are indicated in Table 1.
We can aslo intert picture from a local disk into Rmarkdown by using the following approach:
** Note that the Rmarkdown does support only png and jpeg files. For other image files, Rmarkdown will notify the error of pandoc.exe
Clarens, A.F., E.P. Resurreccoin, M.A. White, and A.M. Colosi. 2010. “Environmental Life Cycle Comparision of Algae to Other Bioenergy Feedstock.” Environmental Sicience Technology 44: 1813–9.
Mutel, Christopher L., and Stefanie Hellweg. 2009. “Regionalized Life Cycle Assessment: Computational Methodology and Application to Inventory Databases.” Environmental Science & Technology 43 (15): 5797–5803. doi:10.1021/es803002j.