Convert .R scripts into a .Rmd file

r2rmd(filepattern = "*.R$", savefile = TRUE, path = ".", savefilename = NA)

Arguments

filepattern

the pattern of the script file names

savefile

logical. Whether to save the output as a file.

path

the path of the folder which contains the .R scripts

savefilename

the destinated file name

Value

an R markdown file

Examples

path <- system.file("examples/r", package = "mindr") r2rmd(path = path)
#> [1] "# Introduction " #> [2] "This file was adapted from < https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.R>." #> [3] "This is a special R script which can be used to generate a report. You can" #> [4] "write normal text in roxygen comments." #> [5] "" #> [6] "# Quick Start " #> [7] "## Options " #> [8] "First we set up some options (you do not have to do this):" #> [9] "" #> [10] "```{r setup, include=FALSE}" #> [11] "library(knitr)" #> [12] "opts_chunk$set(fig.path = 'figure/silk-')" #> [13] "```" #> [14] "" #> [15] "## A Simple Example " #> [16] "The report begins here." #> [17] "" #> [18] "```{r test-a, cache=FALSE}" #> [19] "# boring examples as usual" #> [20] "set.seed(123)" #> [21] "x = rnorm(5)" #> [22] "mean(x)" #> [23] "```" #> [24] "" #> [25] "## Inline Codes " #> [26] "You can use the special syntax {{code}} to embed inline expressions, e.g. {{mean(x) + 2}}" #> [27] "is the mean of x plus 2." #> [28] "The code itself may contain braces, but these are not checked. Thus," #> [29] "perfectly valid (though very strange) R code such as `{{2 + 3}} - {{4 - 5}}`" #> [30] "can lead to errors because `2 + 3}} - {{4 - 5` will be treated as inline code." #> [31] "" #> [32] "## Plots " #> [33] "Now we continue writing the report. We can draw plots as well." #> [34] "" #> [35] "```{r test-b, fig.width=5, fig.height=5}" #> [36] "par(mar = c(4, 4, .1, .1)); plot(x)" #> [37] "```" #> [38] "" #> [39] "## Chunks " #> [40] "Actually you do not have to write chunk options, in which case knitr will use" #> [41] "default options. For example, the code below has no options attached:" #> [42] "" #> [43] "```{r }" #> [44] "var(x)" #> [45] "quantile(x)" #> [46] "```" #> [47] "" #> [48] "And you can also write two chunks successively like this:" #> [49] "" #> [50] "```{r test-chisq5}" #> [51] "sum(x^2) # chi-square distribution with df 5" #> [52] "```" #> [53] "```{r test-chisq4}" #> [54] "sum((x - mean(x))^2) # df is 4 now" #> [55] "```" #> [56] "" #> [57] "Done. Call spin('knitr-spin.R') to make silk from sow's ear now and knit a" #> [58] "lovely purse." #> [59] "## Comments "