jbryer / ipeds

R R package for accessing the Integrated Postsecondary Education Data System (IPEDS) from R.
48 stars 18 forks source link

downloaded file unzips but does not load #19

Open djbauer opened 1 year ago

djbauer commented 1 year ago

Using the download_ipeds function results in an error stating "Problem loading MS Access database file". It is looking for the *.accdb file in the download folder; however, that file actually exists in the unzipped folder, which is a subdirectory of the download folder.

If anyone else encounters this issue, I was able to figure out a workaround. It's not pretty but it's functional. Note that you'll need to change the value for year and the name of the unzipped folder. Here's the workaround:

## get data from IPEDS. this will download the data but will not complete the loading process 
because it expects the .accdb file to appear in the same download folder, but the unzipping 
process creates a new folder. using the try function allows the process to continue after the 
error occurs.

try(download_ipeds(year = 2022, useProvisional = TRUE, cleanup = TRUE))

# identify the unzipped folder
unzipped_folder <- paste0(getIPEDSDownloadDirectory(),"IPEDS202122/")

# make a list of files in the unzipped folder
unzipped_files <- basename(list.files(unzipped_folder))

# move the files from the unzipped folder to the download folder
for (i in unzipped_files){
    file.rename(from = file.path(unzipped_folder, i),
                to = file.path(getIPEDSDownloadDirectory(), i))
}

# now rerun the download_ipeds function. it should complete the loading process.
download_ipeds(year = 2022, useProvisional = TRUE, cleanup = TRUE)

# remove the unzipped folder
unlink(unzipped_folder, recursive = TRUE)
djbauer commented 1 year ago

For additional context, it appears as though this issue begins with the 2021 data; the download_ipeds function works properly for years 2017-2020.

For example, the following code works fine until you get to 2021:

years <- c(2017, 2018, 2019, 2020, 2021, 2022)

for (i in years){
    download_ipeds(year = i, useProvisional = TRUE, cleanup = TRUE)
}