Rmarkdown - html url name different from RScript name?



Hi I have a script that outputs to html format. However, the urlname is the same as the name of the script. I need to have a more web friendly url name. Is there an option to do this?






I can change the url name manually, but would like to know if there is an option inside Rmarkdown.

Thank you.


What is 02-googleAnalyticsR.Rmd knitting as now?


You can change the output file name if you use the rmarkdown::render function as it has argument to customise the rendering process

rmarkdown::render(input = "02-googleAnalyticsR.Rmd", output_file = "new_file_name.html")

Moreover, you can customize this inside your Rmd document using the knit: hook in the YAML header. Using for example an anonymous function

knit: (function(inputFile, encoding) { 
                        output_file='new_file_name.html')) })

With this in the YAML header, when using the knit button in RStudio, this function will be used for rendering. You can use a fix filename like in the example or a computed filename (like with timestamp in it).

More info on this SO question which has some useful links


Hi @mara , is knitting as html_ouput.

This is the YALM part:

title: "Google Analytics en R, dejando de lado Excel"
author: "omar gonzáles díaz"
date: "2 de octubre de 2017"
      in_header: ../header.html
      before_body: ../doc_prefix.html
      after_body: ../after_body.html
    code_folding: show


@cde Thanks Christophe, I’ll look into those!


Right, but what is the name of the file of which that is the YAML header? If it’s 02-googleAnalytics.Rmd and you’re using the Knit button, the resulting html document should, by default, be 02-googleAnalytics.html.

If you want to add 02- to the file name, and your Rmd document is googleAnalytics.Rmd (I’m not sure if this is the second in a series, or if that’s by date, etc.), you can add variable/parameterized elements to that output name as in the R Markdown - variable output name StackOverflow Q&A @cderv recommended!