CancerRegistryOfNorway / NORDCAN

NORDCAN is a database of cancer statistics for the Nordic countries: Denmark, Finland, Iceland, Norway, Sweden, the Faroe Islands, and Greenland.
Other
7 stars 0 forks source link

Reduce length of nordcan.R-script #27

Closed CotterpinDoozer closed 1 year ago

CotterpinDoozer commented 2 years ago

Joonas writes:

In general, I feel the nordcan.R script has become a bit long and contains many lines of code that the user does not need to see with their own eyes. For instance, how the object "._undefined" is handled could be done by writing one or two functions into on of the nordcan R packages and calling them, instead of writing all the code into nordcan.R. Actually "._undefined" should not be done in this way (I wrote that originally). I would now save it into an environment object in one of the nordcan R packages (similarly to how the NORDCAN global settings are currently saved). Then it can be accessed by calling some function written into one of the NORDCAN packages if needed. Something like this:


.__UNDEFINED_ICD10_ENV <- new.env()
undefined_icd10_set <- function(x) {
.__UNDEFINED_ICD10_ENV[["x"]] <- x
NULL
}
undefined_icd10_get <- function() {
.__UNDEFINED_ICD10_ENV[["x"]]
}
undefined_icd10_csv <- function() {
data.table::fwrite(undefined_icd10_get(), path)
}

in function which needs it...

if (has_problem) { warning("there were bad icd10 codes, use nordcanpkg::undefined_icd10_get", "or nordcanpkg::undefined_icd10_csv to see them.") undefined_icd10_set(undefined_icd10_code_dt) }


I don't think the script is so long that we HAVE to shorten it, and sometimes it is also valuable for the user to see some of the commands, but I agree that we should look through it and see if there are some places we can shorten down by using functions. 

I suggest you look through the script to see if there are places like Joonas mentions above which is script on "pure data handling" that the users are not that interested in and see if you can hide those by using functions. Script which gives valuable information on what is happening to the cancer data might be valuable to keep more visible. 
HuidongTian commented 1 year ago

A new version of "nordcan.R" is shortened by wrapping some codes which are not necessarily exposed to users. The updated version is more concise and easy to understand the purpose of each step.

https://github.com/CancerRegistryOfNorway/NORDCAN/blob/master/nordcan_participant_instructions/nordcan.R