epiforecasts / covidregionaldata

An interface to subnational and national level COVID-19 data. For all countries supported, this includes a daily time-series of cases. Wherever available we also provide data on deaths, hospitalisations, and tests. National level data is also supported using a range of data sources as well as linelist data and links to intervention data sets.
https://epiforecasts.io/covidregionaldata/
Other
37 stars 18 forks source link

Functions only work after package is loaded #369

Closed sbfnk closed 3 years ago

sbfnk commented 3 years ago

Running

cases <- covidregionaldata::get_regional_data("UK")

throws an error:

image

unless the covidregionaldata package is loaded first.

seabbs commented 3 years ago

and a deeper issue why is this failing with something related to Colombia when only the UK is used?

seabbs commented 3 years ago

https://github.com/epiforecasts/covidregionaldata/commit/1c32cd7e02323845b8b83dcd9b49e12e7a546dc9 should have fixed the surface issue but leaving open as why Colombia interacts with other classes is an issue.

RichardMN commented 3 years ago

When you call get_regional_data for any country a side effect of finding out which datasets are available is to try to instantiate a class for every country and this will fail for classes which rely on the data loaded as part of the package. We may need to lighten the instantiation which the check of available datasets provides or make a more specific function which just checks that one particular dataset is available - and then figure out what to do about the dependency on the data if the full library hasn’t been loaded.

seabbs commented 3 years ago

Ah, that makes sense Richard, that really is an unintended side effect. I am also surprised it needs to be explicitly loaded in the code (i.e with covidregionaldata:: but perhaps I am not understanding how package namespaces work completely.

I'll open a new issue for this and close this one up as the actual core problem is resolved.