Saving/Loading folders with DrWatson.jl

Hello! I started trying DrWatson out in the hope of tidying up my currently very messy workflow. I’ve run into a problem however - I save two custom types by saving various .csv and .yaml files into a folder. I then load these types by pointing to that folder, i.e.:

save(my_type, save_dir)
my_type = load(::MyType, save_dir)

Is this compatible with the DrWatson workflow somehow?

Hey @gobs - I am a huge fan of DrWatson and would be happy to try to address your question! However, I am a bit confused by what you mean by “custom” types when it seems you only have CSV and yaml files… Could you explain more what you are trying to do?

Offhand, datadir might be of interest for you to check out here: Project Setup · DrWatson

I realize now it’s probably confusing. What I meant was that when I save MyType, it saves a .csv and a .yaml file in a folder. To load an instance of MyType again, I specify the folder where it should be loaded from. This is different to e.g. saving it as a .bson file, so I was wondering if DrWatson could accomodate this, i.e. how can I overload _wsave for my type if that’s even possible?

@Datseris perhaps you could enlighten me on this?


thanks for the interest. As you said yourself, the correct way is to overload _wsave, as is discussed in the opening section here: Saving Tools · DrWatson.

They way to do it is quite simple:

using DrWatson
function DrWatson._wsave(filename::String, x::YourCustomType)
    # whatever saves `x` as a .csv file.

As I don’t know the workings of your type, I’m not sure how you would incorporate tagsave into it. But at least now you get for free safesave and wsave, both of which automatically make the path-to-be-saved (something that FileIO doesn’t do and I find irritating).

1 Like

Maybe it’s time to think about some trait or public API to make this feel less of hack :wink:

1 Like

Thanks @Datseris ! It might be useful to make this more explicit in the documentation. Also does the same apply for _wload (if that exists)?

My original question however is subtlely different - I don’t save my type to a .csv, I save it to a directory which contains the necessary .csv and .yaml files to load the type. My question then was more about whether saving to a directory instead of a file will break any of the functionality of DrWatson?

In general file paths are recoverd through projectdir() and derivatives, so if you can use this then you should be good to go.

_wload doesn’t exist, only wload is necessary!