Firstly, thanks for the very clear and reproducible question. If you look at the source code of the knit2html function, you can understand what the problem is:
R> knit2html function (input, ..., envir = parent.frame(), text = NULL, quiet = FALSE, encoding = getOption("encoding")) { if (is.null(text)) { out = knit(input, envir = envir, encoding = encoding, quiet = quiet) markdown::markdownToHTML(out, outfile <- sub_ext(out, "html"), ...) invisible(outfile) } else { out = knit(text = text, envir = envir, encoding = encoding, quiet = quiet) markdown::markdownToHTML(text = out, ...) } } <environment: namespace:knitr>
If the text argument is NULL (i.e. if you specify the file as input instead of a character vector), then this file is passed to the knit function, and the markdownToHTML function is called as follows:
markdown::markdownToHTML(out, outfile <- sub_ext(out, "html"), ...)
So, in this case, the output file name is generated by replacing the existing file name extension with html , and you cannot provide your own output file name as an argument.
source share