0

Using the data science cookiecutter, how is it possible to keep multiple versions of raw files?

More precisely, if I have two files

data/raw/scrape_2017_06.json
data/raw/scrape_2017_04.json

How can I assure that make always uses the newest version?

akond
  • 15,865
  • 4
  • 35
  • 55
David
  • 1,238
  • 2
  • 13
  • 20

1 Answers1

2

As long as you can relay on file names and sorting those files in raw/data by names in lexical order is equivalent of sorting them by their age, following solution would be enough:

DATAFILE:=$(lastword $(sort $(wildcard data/raw/*.json)))

all:
    @echo The latest datafile is $(DATAFILE)

If not, you need to rely on operating system commands. For Unix system many implementations (certainly, the GNU one) support -t to sort by modification time. So it would be:

DATAFILE:=$(firstword $(shell ls -t data/raw/*.json))
ArturFH
  • 1,697
  • 15
  • 28