lcpilling/ukbrapR

function get_diagnoses fails when run more than once

Closed this issue · 3 comments

Thank you so much for this package!

in my project, the function get_diagnoses only worked the first time that the function was called.

The second time an error appears :

Error in `get_diagnoses()`:
! Could not find file ukbrapr_data/hesin.tsv
Backtrace:
 1. ukbrapR::get_diagnoses(t1d_code)

The reason comes from a difference between how the file_paths$path object is updated during each call.
The first time that the function get_diagnoses is run, file_paths$path is correctly updated line 224.
The second time the function is run file_paths$path is not updated and the files cannot be found.

I found a solution by modifying the line 195
home_path = as.character(Sys.getenv()["HOME"])
by
home_path = as.character(getwd())
by doing so the data are correctly downloaded inside the project and all path are correctly done.

Hi Lauric, thanks for highlighting this!

When the files are copied from the RAP space to the local instance I set it so that they are stored in the users HOME directory, but you are right that the line number 224 to update the paths to reflect this is only done when the files are downloaded, not in later runs. I did not notice this, because the "relative" paths worked fine unless you changed your working directory then tried to run.

Rather the change 195 to become a relative path, I have instead moved line 224 to outside the "download" condition, i.e., the local file paths are now always updated to use the HOME directory. This means the files should always be downloaded there, and it does not matter what the users working directory is (the file paths will always be consistent).

I've created a branch with this fix. Could you check it works for you, then I can push to the main?

remotes::install_github("lcpilling/ukbrapR@issue5")

Thanks again Lauric, great to hear from you.
Luke

Hi Luke,

I like your fix and I can confirm it works in my session.

Fabulous, thanks Lauric.