I have a nextflow workflow for which outputs are saved to a `results` directory. The nextflow `main.nf` script and `rscript.Rmd` are in the `workflow` directory.  

When I run rscript render, the `rscript.Rmd` automatically generates the output in the `workflow` directory rather than the `results` directory as desired.  

To remedy this, I added the parameter output_dir to the render function. However the output ended up at this path: `workflow/work/82/results/run_quality_report.html`. And there was error `Missing output file(s)` 

       publishDir params.outdir, mode:'copy'
    
        output:
        file('run_quality_report.html')
        
        script:
        """
        Rscript -e 'rmarkdown::render(input = "$rscript", output_dir ="${params.outdir}", params = list(directory = "${params.outdir}"))'
        """

Next I tried `output_dir ="$baseDir/${params.outdir}"`. And the output ended up at this path: `results/run_quality_report.html`. But still there was error `Missing output file(s)` 


Does the output need to be at the `.../work/82/results/...html` path with a symbolic link from `results/...html`? Why is nextflow returning Missing output file error? How may I remedy this?


My nextflow.config parameters looks like this 

    params {
    	outdir = "../results"
    }

The rscript header and some snippets looks like this

    output: 
      html_document: 
        toc: true
        toc_float: true
      # runtime: shiny
    params:
      directory:
        value: x
    ...

    ```{r , echo=FALSE, warning=FALSE} 
    inputfile <-read_tsv(file.path(params$directory, "filename.tsv"), show_col_types = FALSE)








https://www.biostars.org/p/9473324/#9473334

You just have to trick rmarkdown to spill the file to the current dir (the nextflow work dir) and Nextflow will then publish it to the outdir. 