I don't know if this is a particularly great solution, but it's too long for a comment, so here goes. I looked at rmarkdown::render
and I don't think what you want is possible unless you redefine render
yourself. Look at line 85 and onwards:
metadata <- paste("\n", "---\n", "title: \"", input,
"\"\n", "author: \"", Sys.info()[["user"]], "\"\n",
"date: \"", date(), "\"\n", "---\n", sep = "")
if (!identical(encoding, "native.enc"))
metadata <- iconv(metadata, to = encoding)
cat(metadata, file = knit_input, append = TRUE)
This isn't controlled by any condition. So a messy way is to redefine render
and replace one of it's lines. I'm borrowing a useful answer to this question: Editing R functions
body(render)[[25]] <- substitute(
if (identical(tolower(tools::file_ext(input)), "r")) {
spin_input <- intermediates_loc(file_with_meta_ext(input,
"spin", "R"))
file.copy(input, spin_input, overwrite = TRUE)
intermediates <- c(intermediates, spin_input)
spin_rmd <- knitr::spin(spin_input, knit = FALSE, envir = envir,
format = "Rmd")
intermediates <- c(intermediates, spin_rmd)
knit_input <- spin_rmd
# Our edited code starts here!
metadata <- paste("\n", "---\n", "title: \"", getOption("yaml_title"), "\"\n",
"author: \"", getOption("yaml_author"), "\"\n", "date: \"",
getOption("yaml_date"), "\"\n", "---\n", sep = "")
# Our edited code ends here!
if (!identical(encoding, "native.enc"))
metadata <- iconv(metadata, to = encoding)
cat(metadata, file = knit_input, append = TRUE)
}
)
Now, my file junk.r
is as follows:
plot(mtcars$mpg, mtcars$hp)
and now render("junk.r")
gives me...

Now you can use options
to use your own entries for title, author and/or date or leave it blank. Of course, it would be easier to edit the .r file or create a .Rmd file but you've ruled those out.