Skip to content

Commit ef60f20

Browse files
committed
change example json & update README
1 parent f97f79f commit ef60f20

13 files changed

+205
-138
lines changed

R/data-json_metadata.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#' Example metadata for a health dataset, to demo the function domain_mapping.R \cr \cr
44
#' This data was created with these five steps:
55
#' \enumerate{
6-
#' \item Go to https://modelcatalogue.cs.ox.ac.uk/hdruk_live/#/catalogue/dataModel/17e86f3f-ec29-4c8e-9efc-8793a74b107d
6+
#' \item Go to https://modelcatalogue.cs.ox.ac.uk/hdruk_live/#/catalogue/dataModel/16920b16-e24c-49f9-b4df-3dc85779822b/dataClasses
77
#' \item Download json metadata file by selecting the 'Export as JSON' option on the download button
88
#' \item \code{install.packages("rjson")}
9-
#' \item \code{json_metadata <- rjson::fromJSON(file = '/browseMetadata/data-raw/maternity_indicators_dataset_(mids)_20240105T132210.json')}
9+
#' \item \code{json_metadata <- rjson::fromJSON(file = '/browseMetadata/data-raw/national_community_child_health_database_(ncchd)_20240405T130125.json')}
1010
#' \item \code{usethis::use_data(json_metadata)}
1111
#' }
1212
#'
@@ -16,5 +16,5 @@
1616
#'
1717
#' @format Nested lists
1818
#'
19-
#' @source https://modelcatalogue.cs.ox.ac.uk/hdruk_live/#/catalogue/dataModel/17e86f3f-ec29-4c8e-9efc-8793a74b107d
19+
#' @source https://modelcatalogue.cs.ox.ac.uk/hdruk_live/#/catalogue/dataModel/16920b16-e24c-49f9-b4df-3dc85779822b/dataClasses
2020
"json_metadata"

R/domain_mapping.R

+8-10
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,14 @@ domain_mapping <- function(json_file = NULL, domain_file = NULL, look_up_file =
181181
} else {
182182
# collect user responses
183183
decision_output <- user_categorisation(selectTable_df$Label[datavar],selectTable_df$Description[datavar],selectTable_df$Type[datavar])
184-
for (d in 1:length(decision_output$decision)) {
185-
# input user responses into output
186-
this_Output <- row_Output
187-
this_Output[nrow(this_Output) + 1 , ] <- NA
188-
this_Output$DataElement[1] <- selectTable_df$Label[datavar]
189-
this_Output$Domain_code[1] <- decision_output$decision[d]
190-
this_Output$Note[1] <- decision_output$decision_note[1]
191-
Output <- rbind(Output,this_Output)
192-
utils::write.csv(Output, output_fname, row.names = FALSE) # save as we go in case session terminates prematurely
193-
}
184+
# input user responses into output
185+
this_Output <- row_Output
186+
this_Output[nrow(this_Output) + 1 , ] <- NA
187+
this_Output$DataElement[1] <- selectTable_df$Label[datavar]
188+
this_Output$Domain_code[1] <- decision_output$decision[1]
189+
this_Output$Note[1] <- decision_output$decision_note[1]
190+
Output <- rbind(Output,this_Output)
191+
utils::write.csv(Output, output_fname, row.names = FALSE) # save as we go in case session terminates prematurely
194192
}
195193
} # end of loop for DataElement
196194

R/user_categorisation.R

+17-17
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ user_categorisation <- function(data_element,data_desc,data_type) {
1919
"\n\nDATA TYPE -----> ", data_type, "\n"
2020
))
2121

22-
# ask user for categorisation
23-
decision <- numeric(0)
24-
cat("\n \n")
25-
cli_alert_info("Categorise this data element (one or multiple domains):")
26-
cat("\n")
27-
while (length(decision) == 0) {
28-
decision <- scan(file="",what=0)
22+
# ask user for categorisation
23+
decision <- character(0)
24+
cat("\n \n")
25+
cli_alert_info("Categorise this data element into one or more domains, e.g. 5 or 5,8:")
26+
cat("\n")
27+
while (length(decision) == 0) {
28+
decision <- scan(file="",what="",n=1)
2929
}
3030

31-
# ask user for note on categorisation
32-
decision_note <- character(0)
33-
cat("\n \n")
34-
cli_alert_info("Write a note to go with this decision (or 'None'):")
35-
cat("\n")
36-
while (length(decision_note) == 0) {
37-
decision_note <- scan(file="",what="",n=1)
38-
}
31+
# ask user for note on categorisation
32+
decision_note <- character(0)
33+
cat("\n \n")
34+
cli_alert_info("Write a note to go with this decision (or 'N'):")
35+
cat("\n")
36+
while (length(decision_note) == 0) {
37+
decision_note <- scan(file="",what="",n=1)
38+
}
3939

40-
return(list(decision = decision,decision_note = decision_note))
40+
return(list(decision = decision,decision_note = decision_note))
4141

42-
}
42+
}

0 commit comments

Comments
 (0)