regex - paste r commands inside rmarkdown file -
i want function place piece of markdown in readme.rmd file. include rcode that executed when new version of readme file rendered.
this want in readme.rmd:
[![last-changedate](https://img.shields.io/badge/last%20change-
r gsub("-", "--", sys.date())-yellowgreen.svg)](/commits/master)"
which @ knitr time turn nicely formated shield date.
however paste in document have escape of characters:
paste0("`r ", "gsub(\"-\", \"--\", sys.date())", "`")
but results [![last-changedate](https://img.shields.io/badge/last%20change-`r gsub(\"-\", \"--\", sys.date())`-yellowgreen.svg)](/commits/master)"
, cannot rendered rmarkdown error: unexpected input: gsub(\ ^....
with suggestion of chinsoon12:
" using single quote works? i.e. use paste0("r ", "gsub('-', '--', sys.date())", "
") "
my problem solved! paste double , single quotes.
paste0("https://img.shields.io/badge/last%20change-", "`r ", "gsub('-', '--', sys.date())", "`", "-yellowgreen.svg")