Hello, I have a parameterized and scheduled rmarkdown document. I would like to customize the knitr::render() function as called by rsconnect so that I can specify the output filename that is automatically distributed to collaborators (by appending Sys.Date() or other).
What's the problem? Here's an example I used one time. Is this what you mean? So you create the rmd file with the document structure and an R script that has a line like this inside a loop.
The key here is that the document is being deployed to the RStudio Connect platform. We are using the Connect Scheduled Output feature to schedule the redeployment and distribution of the document. We are trying to instruct Connect at redeployment to rename the output file from the standard my-report.Rmd -> my-report.html to my-report_foo.html, where foo could be Sys.Date() or ideally a variable from the document itself. This occurs on the Connect server so we can't access the rmarkdown::render() function directly.
That's right. I think the preferred way to do this (that I am aware of) would be to have a "parent" R Markdown document that "renders" a child and then attaches the result to an email. You can then use the pattern referenced there in your link (updated reference here: Posit Connect Documentation Version 2024.02.0 - R Markdown).
There is a way to change the output file of an Rmd from within the Rmd itself, but it seems that this approach does not work on RStudio Connect. However, for your edification it is discussed here:
I'm definitely curious to see if anyone has any other thoughts on how this approach might work! One reason that I suspect Connect enforces the file name convention is that Connect does some network routing to be sure you "see" the right thing in the browser when you visit the app directly. (i.e. it redirects you from /my/app/path to /my/app/path/myfile.html).
I recognize that this is not an ideal workflow, but setting up the parent document and running render() from there is not a whole lot more work and should give you the flexibility that you are looking for! Please report back how it goes, or if you run into any trouble implementing!!