ropensci / drake

An R-focused pipeline toolkit for reproducibility and high-performance computing
https://docs.ropensci.org/drake
GNU General Public License v3.0
1.34k stars 128 forks source link

Function always outdated #1365

Closed jennysjaarda closed 3 years ago

jennysjaarda commented 3 years ago

Sorry in advance for a question without a reproducible example. I thought I would check if you have a quick suggestion as to my mistake. I have one target that is always outdated everytime I start a fresh R session. The target looks like this: ukbb_drug_counts = count_ukbb_drug_users(ukbb_munge_drug_users, drug_codes_interest). The two arguments use upstream targets as inputs: ukbb_munge_drug_users and drug_codes_interest.

The function looks as follows:

count_ukbb_drug_users <- function(ukbb_munge_drug_users, drug_codes_interest){
  data <- ukbb_munge_drug_users %>% dplyr::select(paste0(drug_codes_interest$molecule, "_users")) %>% map_df(~length(which(.==1))) %>% t()
  return(data)
}

Its purpose is to simply count the number of "users" of each drug from a dataset of drug users (0/1 = no/yes). I've included a snapshot of the data below. Is there something obviously wrong with the function such that it would always be outdated? I've tried using deps_code on it, but I don't notice anything. It only takes <1 second to run and it has no downstream targets so for now it's not a huge deal, but I would like to know what I'm doing wrong. Thanks in advance!

loadd(ukbb_munge_drug_users)
loadd(drug_codes_interest)

head(ukbb_munge_drug_users)
      eid amisulpride_users aripiprazole_users clozapine_users
1 4845585                 0                  0               0
2 2326469                 0                  0               0
3 3665794                 0                  0               0
4 3647543                 0                  0               0
5 1303873                 0                  0               0
6 4818681                 0                  0               0
  mirtazapine_users olanzapine_users quetiapine_users risperidone_users
1                 0                0                0                 0
2                 0                0                0                 0
3                 0                0                0                 0
4                 0                0                0                 0
5                 0                0                0                 0
6                 0                0                0                 0
  valproate_users
1               0
2               0
3               0
4               0
5               0
6               0

drug_codes_interest$molecule

[1] "amisulpride"  "aripiprazole" "clozapine"    "mirtazapine"  "olanzapine"  
[6] "quetiapine"   "risperidone"  "valproate"  

count_ukbb_drug_users(ukbb_munge_drug_users, drug_codes_interest)
                   [,1]
amisulpride_users   181
aripiprazole_users   78
clozapine_users      57
mirtazapine_users  1432
olanzapine_users    615
quetiapine_users    359
risperidone_users   310
valproate_users    1495
wlandau commented 3 years ago

I am not sure what the issue could be. I assume the error goes away when you try to create a reprex? Could it be that you have an outdated copy of count_ukbb_drug_users() somewhere else in your code which overwrites the count_ukbb_drug_users() you expect to have?