Update download.R to allow year vectors for baci data #250
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the bug
While downloading BACI data for single years is functional, downloding data from a vector of years raises errors. Say, seting
year = 1995:2022
to download the entire series. The result is the following:Causes
The
year
parameter is used both for data cleaning and for downloading from the sources, when data for each year has a different url. But for Baci data, download is done from a single url, so we don’t need to generate a path for each year.The download path is first defined as:
Which would work. But, to account for sources with different urls by year, we have:
If the user-provided
year
is a one-length vector or NULL, nothing changes and the download proceeds. But if we have an n-length vector,path
also becomes a vector, with n repetitions of the url.Then the download operation below raises the error I presented in the beginning:
Workaround year = NULL fails
The possible workaround of doing
year = NULL
downloads everything todat
, including files “country_codes_V202401b” and “product_codes_HS92_V202401b”, since the regex only has the term “V202401b” now.So
rbindlist()
inbaci.R
fails, returning:Solution
I added a new (simple) exception to the definition of the download path in
external_download
. It ensures 'path' is the single url in 'param$url' when sourcing baci files.