Pweave icon indicating copy to clipboard operation
Pweave copied to clipboard

Pass argument to the script

Open liborw opened this issue 6 years ago • 7 comments

Is there a way how to pass command line arguments to the script?

liborw avatar Oct 30 '18 20:10 liborw

pweave --help should provide some answers, otherwise you should explain what script you are talking about.

piccolbo avatar Oct 30 '18 21:10 piccolbo

The idea is that i have Pweave document (script), which generates report, now I would like to generate same report for different input data, ideally without the need to change the document itself, so is there a way how to pass parameters when I'm generating the report:

$ pweave FIR_design.pmd data.csv

liborw avatar Nov 22 '18 11:11 liborw

Maybe something like: $ pweave script.texw --args 'data.csv' ?

abukaj avatar Nov 22 '18 12:11 abukaj

Yes that would be great.

liborw avatar Nov 22 '18 14:11 liborw

Nice idea! A few comments.

  1. This seems related to parametrized reports in R. I think we should take a look at that design and see what we can learn.
  2. This looks like a major feature to me. We may have to wait for creator @mpastell to have a bit more time availability.
  3. What about workarounds. What if your pweave doc just opened a file named "data.csv"? Is that clearly inferior?

piccolbo avatar Nov 23 '18 18:11 piccolbo

  1. What about workarounds. What if your pweave doc just opened a file named "data.csv"? Is that clearly inferior?

I use 'config.ini' to pass necessary arguments (including filenames) to my scripts, but there is still a problem that I need to edit it every time I want to weave with different parameters.

How about something like:

$ echo 'data.csv' > .config.txt; pweave script.texw

with script.texw looking like that:

<<>>=
argv = open('.config.txt').readlines()
@

abukaj avatar Nov 23 '18 20:11 abukaj

I would like to add my vote for this feature as well. I would prefer the simplicity of @abukaj's suggestion over something like how parameterized reports works in R. Right now I have a variable inside the script that I change for different datasets but is inelegant and clunky. I'm considering creating a wrapper function to first create the file as suggested with supplied arguments.

MatthewFlamm avatar Jan 16 '19 19:01 MatthewFlamm