There are many instances where we have numerous targets and/or sources to be specified.
Here we'll consider a hypothetical example where:
- A script named
inflation_plots.Rinsource/analysis/plotstakes monthly inflation data for Germany, France, and Turkey for the years 1980, 1990, 2000, 2010, and 2020 fromdatastore/raw/inflation, and outputs monthly time-series plots for each country-year tooutput/analsis/plots. - Assume that the names of the raw files have the form
countrycode_year.csv(e.g.FR_1990.csv) and output files have the formcountrycode_year.pngandcountrycode_year.eps.
For source files, we suggest using Glob(), as in:
source = ['#source/analysis/plots/inflation_plots.R',
Glob('#datastore/raw/inflation/*.csv')]
For target files, we suggest using one of the following:
- Loops
An example:
target = []
for country in ['FR', 'DE', 'TR']:
for year in ['1980', '1990', '2000', '2010', '2020']:
target += [
'#output/analysis/plots/%s_%s.eps' % (country, year),
'#output/analysis/plots/%s_%s.png' % (country, year),
]
list_files.py
Alternatively, you can use source/lib/list_files.py.
- Using a terminal, to get a list of the files in
output/analysis/plots, you can write:
python source/lib/list_files.py output/analysis/plots
- To get a list of files in the same folder with
.epsextension, you can write:
python source/lib/list_files.py output/analysis/plots --patterns "*.eps"
- By default, this script follows
gitignorerules, i.e. it doesn't return files that are ignored by Git. To override this, use:
python source/lib/list_files.py output/analysis/plots --no-git --patterns "*.eps"