Skip to content

I1728: Create burden estimate templates in jenner #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

xiangli313
Copy link
Contributor

Youtrack:
https://vimc.myjetbrains.com/youtrack/issue/VIMC-1728

Task:
Move Nick's script - generate burden templates - to jenner

Past test:
Yes, locally. You need to pull from jenner-test-data. I added test data.

@xiangli313 xiangli313 self-assigned this Apr 30, 2018
@xiangli313 xiangli313 requested a review from richfitz May 3, 2018 13:16
Copy link
Member

@richfitz richfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be most efficient to work through this one together Xiang - can you pick a time next week?

@@ -11,7 +11,8 @@ Imports:
RPostgres,
vaultr,
whisker,
yaml
yaml,
dplyr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally minor, but can you order dependencies alphabetically please (but capitals first) - so this goes just above vaultr

assert_has_files <- function(x, files) {
msg <- setdiff(files,x)
if (length(msg) > 0L) {
stop(sprintf("Missing file '%s' from: %s.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will behave badly if there are more than one missing file (try it!). Once you've tried it can you write some unit tests for practice?

##' @export
create_burden_template <- function(files, files_path, assert_files = c("Country_Disease_Table.csv", "model_meta.csv", "model_outcomes.csv"), central_templates_only = FALSE) {
assert_has_files(files, assert_files)
files <- paste0(files_path, files)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use file.path to construct full paths (deals with the case where files_path does not include a trailing slash for example

##'
##' @param files_path the directory that contains those files above
##'
##' @param assert_files needed meta files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused about this - why is this an argument to the function?

assert_has_files(files, assert_files)
files <- paste0(files_path, files)

country_disease_table <- read_csv(files[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fragile, and the interface is a bit odd, really. I think what you're wanting is:

  • the user provides a directory
  • by default we look for a pre-defined set of csv files
  • the user can override that with their own name?

But this is not quite what happens - you assert the presence of a set of files in assert_files and then read files in order


model_name <- unique(model_meta_data[model_meta_data$disease == disease_name[j], ]$modelling_group)

sapply(1:length(model_name), generate_csv, model_name, j)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate_csv returns nothing so don't use csv, use a for loop. Avoid 1:length(foo) in favour of seq_along(foo)


}

if (disease_name[j] != "HPV") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an else against the previous if


outcome_name <- unique(model_outcomes[model_outcomes$disease == "standard" & model_outcomes$model == "standard", ]$outcome)

if (disease_name[j] == "Hib3" & model_name[i] == "JHU-Tam") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there so much repetition here?

write.csv(country_data_stochastic, file = title_stochastic, row.names = FALSE)
write.csv(country_data, file = title, row.names = FALSE)

return()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

return(countries_for_model)
}

make_filled_columns <- function(model_meta_line,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use a more informative name here?

@xiangli313
Copy link
Contributor Author

OK, what we have here is Nick's R-style. It may take me some time to understand those functions and clear those requested/suggested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants