Thanks, this works great. It even recognizes objects previously declared.
a <- 1:5
markobj <- c('---',
'title: "test"',
'output: html_document',
'---',
'',
'## R Markdown',
'',
'This is an R Markdown document.',
'```{r}',
'b <- 11:15',
'print(a)',
'print(b)',
'```')
markdown::markdownToHTML(text = knitr::knit(text = markobj), output = 'test.html')
browseURL("test.html")