trashbirdecology / bbsAssistant

An R package for downloading and handling data and information from the North American Breeding Bird Survey.
Creative Commons Zero v1.0 Universal
27 stars 13 forks source link

Dir.create should have recursive=TRUE option when it's called in get_bbs_data() #109

Closed brendanwallison closed 2 years ago

brendanwallison commented 2 years ago

I'm using R 4.1.1 and the most recent version of bbsAssistant as of 10/09/2021 in Windows 10. The get_bbs_data function kept failing every time I called it with the following code:

devtools::install_github("trashbirdecology/bbsAssistant", ref="main", force=TRUE) 
library(bbsAssistant)
sb_id = "5ea04e9a82cefae35a129d65"
data2 = get_bbs_data(sb_id)

Resulting in:

Error in curl::curl_fetch_disk(url, x$path, handle = handle) : Failed to open file C:\Dev\Classes\Spatial Ecology\HW2\data-raw\5ea04e9a82cefae35a129d65\50-StopData.zip.

Digging into things a little bit more, it was simply because it was failing to create the directory to dump the data into (the default behavior is to create a 'data-raw' folder, then a folder based on the sb_id inside of that, but by default dir.create() cannot create directories recursively in this manner).

The error message came a bit later because suppressWarnings() wrapped up the actual point of failure:

# Create sb_dir -----------------------------------------------------------
suppressWarnings(dir.create(sb_dir)) # create directory for data associated with the sb item (sb_id) if it does not already exist. 

This fixed it for me:

dir.create(sb_dir, recursive=TRUE)
trashbirdecology commented 2 years ago

@brendanwallison , I am so sorry for some reason my notifications were turned off for this repository and I have missed....quite a few. This has been updated in major update branch, soon to be merged into main.