Skip to content

Suggestion: Declare script as input #1

@mfansler

Description

@mfansler

Nice example - I came here from the SO answer.

Unlike the other rule that uses a script: key, the use of shell: key shown below means that Snakemake will not track the dependency between this rule and the scr/test-script.R file:

shell:
"Rscript scr/test-script.R \
--input {input.data} \
--output {output.out} \
--myFactor {params.myFactor}"

I would recommend it as better practice to

  • declare the script in the input:
    input:
      script='scr/test-script.R',
      data='data/testData.rds'
  • use that Jinja variable in the shell: command, e.g., RScript {input.script} ...

This way, if the script has changes made to it, Snakemake can use them to invalidate any downstream objects that may have used an older version.

At least, that's what I picked up from using that style of integration (custom arguments to the scripts) for a couple years. Personally, I moved on to favor the script: style (using the snakemake object), and find it clearer to maintain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions