This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Running Rscript in Nextflow (Rmd file not found)

I have a nextflow DSL2 workflow which uses an Rscript in one of the processes. However when running the workflow (on a HPC cluster), the .Rmd file is not found. I tried various ways of referring to the file/path.

The path to the .Rmd file is defined as a param in the config file.

params {
    rscript = "./myscript.Rmd"
}
process {
    withName: run_report {
        conda = './env_R.yml'
    }   
} 

Process like this:

  rscript = file(params.rscript)
  ...
   process run_report {
    ...
    input:
    ...
    path(rscript)
    output:
    ...
    script:
    """
    Rscript -e "rmarkdown::render("$rscript")"
    """
}

I also tried this, directly referencing the .Rmd file and a variation like Rscript -e "rmarkdown::render("./myscript.Rmd")"

   process run_report {     
        ...
        script:
        """
        Rscript -e "rmarkdown::render("myscript.Rmd")"
        """
    }

Env file

name: R_kn
channels: 
  - defaults
  - conda-forge
dependencies: 
  - r-base=4.2.2
  - r-rmarkdown
rscript r nextflow

Could you try with absolute path to file?

1) Does it work on your local machine? 2) What is the exact error message you get? 3) Could you please share your .nextflow.log file? 4) Can you share the tree structure of your work dir? (Use the tree command)

Hi. Thank you for the tips. The accepted answer resolved my issue. It was due to the wrong use of quotes.

1 answer

Rscript -e "rmarkdown::render("$rscript")"

you're using a double quote string inside a double quote string...

try

Rscript -e 'rmarkdown::render("$rscript")'

and use a full path for params.rscript

Thank you! This resolved the issue! I will pay better attention to double quote strings vs single quote strings!

Log in to answer this question.