Skip to content

Commit

Permalink
Merge pull request #156 from aim-rsf/examples
Browse files Browse the repository at this point in the history
Add examples to functions
  • Loading branch information
RayStick authored Nov 28, 2024
2 parents d39f0a0 + 0bb4265 commit 2ebdb2a
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/browse_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' for this dataset. Open the two html output files in your browser and use
#' these as reference when running the map_metadata function.
#' @examples
#' # Demo run
#' # Demo run requires no function inputs or user interaction
#' browse_metadata()
#' @export
#' @importFrom dplyr %>% add_row
Expand Down
2 changes: 1 addition & 1 deletion R/map_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' mappings and 'LOG_' which contains details about the dataset and session.
#' @examples
#' \dontrun{
#' # Demo run - requires user interactions
#' # Demo run requires no function inputs but requires user interaction
#' map_metadata()
#' }
#' @export
Expand Down
23 changes: 20 additions & 3 deletions R/map_metadata_compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@
#'
#' @param session_dir This directory should contain 2 csv files for each session (LOG_ and OUTPUT_), 4 csv files in total.
#' @param session1_base Base file name for session 1 e.g. 'NationalCommunityChildHealthDatabase(NCCHD)_BLOOD_TEST_2024-07-05-16-07-38'
#' @param session2_base Base file name for session 1 e.g. 'NationalCommunityChildHealthDatabase(NCCHD)_BLOOD_TEST_2024-07-08-12-03-30'
#' @param session2_base Base file name for session 2 e.g. 'NationalCommunityChildHealthDatabase(NCCHD)_BLOOD_TEST_2024-07-08-12-03-30'
#' @param json_file The full path to the metadata file used when running map_metadata (should be the same for session 1 and session 2)
#' @param domain_file The full path to the domain file used when running map_metadata (should be the same for session 1 and session 2)
#' @return It returns a csv output, which represents the consensus decisions between session 1 and session 2
#' @export
#' @importFrom utils read.csv write.csv
#' @importFrom jsonlite fromJSON
#' @importFrom cli cli_alert_success

#' @examples
#' \dontrun{
#' # Locate file paths for the example files in the package
#' demo_session_dir <- system.file("outputs", package = "browseMetadata")
#' demo_session1_base <- "NationalCommunityChildHealthDatabase(NCCHD)_CHILD_2024-11-27-14-19-55"
#' demo_session2_base <- "NationalCommunityChildHealthDatabase(NCCHD)_CHILD_2024-11-27-14-23-52"
#' demo_json_file <- system.file("inputs", "national_community_child_health_database_(ncchd)_20240405T130125.json", package = "browseMetadata")
#' demo_domain_file <- system.file("inputs", "domain_list_demo.csv", package = "browseMetadata")
#'
#' # Run the function - requires user interaction
#' map_metadata_compare(
#' session_dir = demo_session_dir,
#' session1_base = demo_session1_base,
#' session2_base = demo_session2_base,
#' json_file = demo_json_file,
#' domain_file = demo_domain_file
#' )
#' }
map_metadata_compare <- function(session_dir, session1_base, session2_base, json_file, domain_file) {
timestamp_now_fname <- format(Sys.time(), "%Y-%m-%d-%H-%M-%S")

Expand Down Expand Up @@ -110,7 +127,7 @@ map_metadata_compare <- function(session_dir, session1_base, session2_base, json
table_find <- data.frame(table_n = numeric(length(dataset$childDataClasses)), table_label = character(length(dataset$childDataClasses)))
for (t in 1:length(dataset$childDataClasses)) {
table_find$table_n[t] <- t
table_find$table_label[t] <- dataset$childDataClasses[[t]]$label
table_find$table_label[t] <- dataset$childDataClasses$label[t]
}
table_n <- table_find$table_n[table_find$table_label == csv_1a$table[1]]

Expand Down
8 changes: 7 additions & 1 deletion R/map_metadata_convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
#' @return The function will return 'L-OUTPUT_' in the same output_dir
#' @export
#' @importFrom utils read.csv write.csv

#' @examples
#' # Locate file path and file name for the example files in the package
#' demo_output_dir <- system.file("outputs", package = "browseMetadata")
#' demo_output_csv <- "OUTPUT_NationalCommunityChildHealthDatabase(NCCHD)_CHILD_2024-11-27-14-19-55.csv"
#'
#' # Run the function
#' map_metadata_convert(output_csv = demo_output_csv, output_dir = demo_output_dir)
map_metadata_convert <- function(output_csv, output_dir) {
output <- read.csv(paste0(output_dir, "/", output_csv))
output_long <- output[0, ] # make duplicate
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
},
"SystemRequirements": null
},
"fileSize": "753.382KB",
"fileSize": "1085.556KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"timestamp","browseMetadata","initials","metadata_version","metadata_last_updated","domain_list_desc","dataset","table","table_note"
"2024-11-27 14:19:55",2.0.1,"demo","16.0.0","2024-03-14T17:40:57.463Z","DemoList","National Community Child Health Database (NCCHD)","CHILD","demo run"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"timestamp","browseMetadata","initials","metadata_version","metadata_last_updated","domain_list_desc","dataset","table","table_note"
"2024-11-27 14:23:52",2.0.1,"demo2","16.0.0","2024-03-14T17:40:57.463Z","DemoList","National Community Child Health Database (NCCHD)","CHILD","demo2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"timestamp","table","data_element_n","data_element","domain_code","note"
"2024-11-27 14:19:55","CHILD","1 of 35","ALF_E","2","AUTO CATEGORISED"
"2024-11-27 14:19:55","CHILD","2 of 35","ALF_MTCH_PCT","2","AUTO CATEGORISED"
"2024-11-27 14:19:55","CHILD","3 of 35","ALF_STS_CD","2","AUTO CATEGORISED"
"2024-11-27 14:19:55","CHILD","4 of 35","APGAR_1","7",""
"2024-11-27 14:19:55","CHILD","5 of 35","APGAR_2","7",""
"2024-11-27 14:19:55","CHILD","6 of 35","AVAIL_FROM_DT","1","AUTO CATEGORISED"
"2024-11-27 14:19:55","CHILD","7 of 35","BIRTH_ORDER","7","10% missingess"
"2024-11-27 14:19:55","CHILD","8 of 35","BIRTH_TM","1,7","20% missingess"
"2024-11-27 14:19:55","CHILD","9 of 35","BIRTH_WEIGHT","7",""
"2024-11-27 14:19:55","CHILD","10 of 35","BIRTH_WEIGHT_DEC","7",""
"2024-11-27 14:19:55","CHILD","11 of 35","BREASTFEED_8_WKS_FLG","7",""
"2024-11-27 14:19:55","CHILD","12 of 35","BREASTFEED_BIRTH_FLG","7",""
"2024-11-27 14:19:55","CHILD","13 of 35","CHILD_ID_E","2",""
"2024-11-27 14:19:55","CHILD","14 of 35","CURR_LHB_CD_BIRTH","5,7","Place of birth"
"2024-11-27 14:19:55","CHILD","15 of 35","DEL_CD","7",""
"2024-11-27 14:19:55","CHILD","16 of 35","DOD","3,7",""
"2024-11-27 14:19:55","CHILD","17 of 35","ETHNIC_GRP_CD","3",""
"2024-11-27 14:19:55","CHILD","18 of 35","GEST_AGE","3,7",""
"2024-11-27 14:19:55","CHILD","19 of 35","GNDR_CD","3","AUTO CATEGORISED"
"2024-11-27 14:19:55","CHILD","20 of 35","HEALTH_VISITOR_CD_E","2",""
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"timestamp","table","data_element_n","data_element","domain_code","note"
"2024-11-27 14:23:52","CHILD","1 of 35","ALF_E","2","AUTO CATEGORISED"
"2024-11-27 14:23:52","CHILD","2 of 35","ALF_MTCH_PCT","2","AUTO CATEGORISED"
"2024-11-27 14:23:52","CHILD","3 of 35","ALF_STS_CD","2","AUTO CATEGORISED"
"2024-11-27 14:23:52","CHILD","4 of 35","APGAR_1","7",""
"2024-11-27 14:23:52","CHILD","5 of 35","APGAR_2","7",""
"2024-11-27 14:23:52","CHILD","6 of 35","AVAIL_FROM_DT","1","AUTO CATEGORISED"
"2024-11-27 14:23:52","CHILD","7 of 35","BIRTH_ORDER","1,7",""
"2024-11-27 14:23:52","CHILD","8 of 35","BIRTH_TM","7",""
"2024-11-27 14:23:52","CHILD","9 of 35","BIRTH_WEIGHT","7",""
"2024-11-27 14:23:52","CHILD","10 of 35","BIRTH_WEIGHT_DEC","7",""
"2024-11-27 14:23:52","CHILD","11 of 35","BREASTFEED_8_WKS_FLG","7",""
"2024-11-27 14:23:52","CHILD","12 of 35","BREASTFEED_BIRTH_FLG","7",""
"2024-11-27 14:23:52","CHILD","13 of 35","CHILD_ID_E","2",""
"2024-11-27 14:23:52","CHILD","14 of 35","CURR_LHB_CD_BIRTH","5,7",""
"2024-11-27 14:23:52","CHILD","15 of 35","DEL_CD","7",""
"2024-11-27 14:23:52","CHILD","16 of 35","DOD","3",""
"2024-11-27 14:23:52","CHILD","17 of 35","ETHNIC_GRP_CD","3",""
"2024-11-27 14:23:52","CHILD","18 of 35","GEST_AGE","7",""
"2024-11-27 14:23:52","CHILD","19 of 35","GNDR_CD","3","AUTO CATEGORISED"
"2024-11-27 14:23:52","CHILD","20 of 35","HEALTH_VISITOR_CD_E","0,1",""
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/browse_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/map_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion man/map_metadata_compare.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/map_metadata_convert.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2ebdb2a

Please sign in to comment.