Convert .md or .Rmd files into a .R script

rmd2r(filepattern = "*.[R]*md$", path = ".", savefile = TRUE, savefilename = NA,
    backup = TRUE, heading = " --------", chunkheading = FALSE)

Arguments

filepattern

the pattern of the file names

path

the path of the folder which contains the .Rmd or .md files

savefile

logical. Whether to save the output as a file.

savefilename

the destinated file name

backup

logical. whether backup the existent file

heading

the indicator of the headings

chunkheading

logical. whether treat chunk options as headings (ending with ----)

Value

a .R script

Examples

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