RStudio Connect does not seem to allow me to publish a parameterized RMarkdown that sources a script using the parameters. For example, I created the following test RMarkdown file:
However, I think your problem is that the params variable is not available in the context you are trying to use it in. I would add some debugging lines like print(capture.output(str(params))) or look at the options to source and whether it allows for setting the environment that your script is running in.
Generally for this type of "sub-script," I would recommend making the "child" document an R Markdown script and looking into rmarkdown::render() , because you have lots of controls over the environment that it is executed in, and can even pass parameters like rmarkdown::render(params = list(myparam = "something")).
Do you have this source stored somewhere on GitHub / etc. so that others could easily try it?
Adding local = TRUE as an option to source fixes the problem! When local = TRUE, the expressions in the script are evaluated in the environment from which source is called, so it can access the parameters. I created a GitHub repository for this code here: https://github.com/babichmorrowc/rsc_test, so you can see how the code looks.
As a side note, adding the following to the YAML does not solve the problem and is not nessary: