Nextflow R Markdown render output to different directory: Missing output file(s)
1
2
Entering edit mode
16 months ago
Eliveri ▴ 350

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)
rstudio r rmarkdown nextflow • 1.3k views
ADD COMMENT
4
Entering edit mode
16 months ago
ATpoint 82k

Render Rmarkdown in nextflow

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.

ADD COMMENT
0
Entering edit mode

Thank you so much! I had been stuck on this for days! The solution is so simple!

ADD REPLY
1
Entering edit mode

Indeed, sometimes it is so easy that we miss it. I was also stuck quite some time on that when I used Nextflow+rmarkdown for the first time. In our defense, rmarkdown is a little annoying in the regard that it puts outputs into the folder where the script is located and not to the current directory from where it is executed, and that that clashes with how Nextflow sees things :)

ADD REPLY

Login before adding your answer.

Traffic: 1555 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6