lodown icon indicating copy to clipboard operation
lodown copied to clipboard

NSDUH Catalog

Open tlcaputi opened this issue 2 years ago • 1 comments

lodown is an excellent project that I've enjoyed for several years now. However, it seems the NSDUH functions may need an update:

Reproducible example (from http://asdfree.com/national-study-on-drug-use-and-health-nsduh.html):

library(lodown)
devtools::install_github( "ajdamico/lodown" , dependencies = TRUE )

# examine all available NSDUH microdata files
nsduh_cat <-
  get_catalog( "nsduh" ,
               output_dir = file.path( path.expand( "~" ) , "NSDUH" ) )

# 2016 only
nsduh_cat <- subset( nsduh_cat , year == 2016 )
# download the microdata to your local computer
nsduh_cat <- lodown( "nsduh" , nsduh_cat )

Output (catalog won't build):

> library(lodown)
> # examine all available NSDUH microdata files
> nsduh_cat <-
+   get_catalog( "nsduh" ,
+                output_dir = file.path( path.expand( "~" ) , "NSDUH" ) )
building catalog for nsduh

Error in data.frame(year = link_year, full_url = link_url, output_filename = paste0(output_dir,  : 
  arguments imply differing number of rows: 0, 1
> 
> # 2016 only
> nsduh_cat <- subset( nsduh_cat , year == 2016 )
Error in subset(nsduh_cat, year == 2016) : object 'nsduh_cat' not found
> # download the microdata to your local computer
> nsduh_cat <- lodown( "nsduh" , nsduh_cat )
Error in lodown("nsduh", nsduh_cat) : object 'nsduh_cat' not found

Expected Behavior: Download 2016 NSDUH into ~/NSDUH

System Info:

> R.Version()
$platform
[1] "x86_64-w64-mingw32"

$arch
[1] "x86_64"

$os
[1] "mingw32"

$system
[1] "x86_64, mingw32"

$status
[1] ""

$major
[1] "4"

$minor
[1] "0.0"

$year
[1] "2020"

$month
[1] "04"

$day
[1] "24"

$`svn rev`
[1] "78286"

$language
[1] "R"

$version.string
[1] "R version 4.0.0 (2020-04-24)"

$nickname
[1] "Arbor Day"

Comments: Let me know if you have trouble reproducing my error. Thank you for this excellent project!

tlcaputi avatar Oct 28 '21 02:10 tlcaputi

thanks! it would be great if you could propose a fix with a pull request

ajdamico avatar Oct 28 '21 10:10 ajdamico