|
7 | 7 | #' You can add your custom questions to this questionnaire and then pass it to this |
8 | 8 | #' function to process the data. |
9 | 9 | #' |
10 | | -#'@param data Biodiversity data in a data frame |
11 | | -#'@param customQuestionnaire Custom user created questionnaire responses if to pypass answering questions each time. |
12 | | -#'@param clean Whether to clean after flagging. If false only flagging will be done. |
13 | | -#'@param missing How to treat data with missing values. Default: false - will be treated as bad data. |
14 | | -#'@param report Whether to print report of cleaning done. |
15 | | -#'@param format Formats of the cleaning report required. Options are: Markdown, HTML or / and PDF |
| 10 | +#' @param data Biodiversity data in a data frame |
| 11 | +#' @param custom_questionnaire Custom user created questionnaire responses if to pypass answering questions each time. |
| 12 | +#' @param clean Whether to clean after flagging. If false only flagging will be done. |
| 13 | +#' @param missing How to treat data with missing values. Default: false - will be treated as bad data. |
| 14 | +#' @param report Whether to print report of cleaning done. |
| 15 | +#' @param format Formats of the cleaning report required. Options are: Markdown, HTML or / and PDF |
16 | 16 | #' |
17 | | -#'@return data frame with clean data |
| 17 | +#' @return data frame with clean data |
18 | 18 | #' |
19 | | -#'@examples \dontrun{ |
20 | | -#'library(rgbif) |
21 | | -#'occdat <- occ_data( |
22 | | -#' country = "AU", # Country code for australia |
23 | | -#' classKey= 359, # Class code for mammalia |
24 | | -#' limit=5000 # Get only 5000 records |
25 | | -#' ) |
26 | | -#' myData<-occdat$data |
27 | | -#' |
28 | | -#' cleanedData <- clean_data(myData) |
29 | | -#' |
30 | | -#' responses <- run_questionnaire() |
31 | | -#' cleanedData <- clean_data(myData, responses) |
32 | | -#' |
33 | | -#' customQuestionnaire <- create_default_questionnaire() |
34 | | -#' customResponses <- run_questionnaire(customQuestionnaire) |
35 | | -#' cleanedData <- clean_data(myData, customResponses) |
36 | | -#' } |
| 19 | +#' @examples |
| 20 | +#' |
| 21 | +#' custom_questionnaire <- create_default_questionnaire() |
| 22 | +#' |
| 23 | +#' if(interactive()){ |
| 24 | +#' |
| 25 | +#' library(rgbif) |
| 26 | +#' occdat <- occ_data( |
| 27 | +#' country = 'AU', # Country code for australia |
| 28 | +#' classKey = 359, # Class code for mammalia |
| 29 | +#' limit = 50 # Get only 50 records |
| 30 | +#' ) |
| 31 | +#' myData <- occdat$data |
| 32 | +#' |
| 33 | +#' responses <- run_questionnaire() |
| 34 | +#' cleaned_data <- clean_data(myData, responses) |
| 35 | +#' |
| 36 | +#' cleaned_data2 <- clean_data(myData) |
| 37 | +#' |
| 38 | +#' } |
37 | 39 | #' |
38 | | -#'@export |
| 40 | +#' @export |
39 | 41 | clean_data <- |
40 | 42 | function(data, |
41 | | - customQuestionnaire = NULL, |
| 43 | + custom_questionnaire = NULL, |
42 | 44 | clean = TRUE, |
43 | 45 | missing = FALSE, |
44 | 46 | report = TRUE, |
45 | 47 | format = c("html_document", "pdf_document")) { |
46 | 48 | responses <- list() |
47 | | - inputData <- data |
48 | | - flaggedData <- data |
49 | | - cleanedData <- data |
50 | | - |
| 49 | + input_data <- data |
| 50 | + flagged_data <- data |
| 51 | + cleaned_data <- data |
51 | 52 |
|
52 | 53 | # Questionnaire |
53 | | - if (is.null(customQuestionnaire)) { |
| 54 | + if (is.null(custom_questionnaire)) { |
54 | 55 | responses <- run_questionnaire() |
55 | 56 | } else { |
56 | | - responses <- customQuestionnaire |
| 57 | + responses <- custom_questionnaire |
57 | 58 | } |
58 | 59 |
|
59 | 60 | # Flagging |
60 | | - flaggedData <- responses$flagData(inputData, missing) |
61 | | - |
| 61 | + flagged_data <- responses$flag_data(input_data, missing) |
62 | 62 |
|
63 | 63 | # Decision Making |
64 | 64 | if (clean) { |
65 | | - cleanedData <- cleaning_function(flaggedData) |
| 65 | + cleaned_data <- cleaning_function(flagged_data) |
66 | 66 | } |
67 | 67 |
|
68 | 68 | # Report |
69 | 69 | if (report) { |
70 | 70 | create_report_data(data, |
71 | | - flaggedData, |
72 | | - cleanedData, |
| 71 | + flagged_data, |
| 72 | + cleaned_data, |
73 | 73 | responses, |
74 | 74 | clean, |
75 | 75 | format) |
76 | 76 | } |
77 | 77 |
|
78 | 78 | # Cleaning |
79 | 79 | if (clean) { |
80 | | - return(cleanedData) |
| 80 | + return(cleaned_data) |
81 | 81 | } |
82 | 82 |
|
83 | | - return(flaggedData) |
| 83 | + return(flagged_data) |
84 | 84 | } |
85 | 85 |
|
86 | 86 |
|
87 | 87 | #' Execute the Questionnaire and save user responses. |
88 | 88 | #' |
89 | 89 | #' |
90 | | -#'@param customQuestionnaire Custom User Created Questionnaire if already available. |
| 90 | +#' @param custom_questionnaire Custom User Created Questionnaire if already available. |
91 | 91 | #' |
92 | | -#'@return list with BdQuestionObjects containing user answers |
| 92 | +#' @return list with BdQuestionObjects containing user answers |
93 | 93 | #' |
94 | | -#'@examples \dontrun{ |
95 | | -#'library(rgbif) |
96 | | -#'occdat1 <- occ_data( |
97 | | -#' country = "AU", # Country code for australia |
98 | | -#' classKey= 359, # Class code for mammalia |
99 | | -#' limit=5000, # Get only 5000 records |
100 | | -#' ) |
101 | | -#' myData<-occdat1$data |
| 94 | +#' @examples |
| 95 | +#' |
| 96 | +#' if(interactive()){ |
102 | 97 | #' |
103 | | -#' responses <- run_questionnaire() |
104 | | -#' cleanedData <- clean_data_new(myData, responses) |
105 | | -#'} |
| 98 | +#' responses <- run_questionnaire() |
| 99 | +#' |
| 100 | +#' } |
106 | 101 | #' |
107 | | -#'@export |
108 | | -run_questionnaire <- function(customQuestionnaire = NULL) { |
| 102 | +#' @export |
| 103 | +run_questionnaire <- function(custom_questionnaire = NULL) { |
109 | 104 | responses <- list() |
110 | | - |
111 | | - if (is.null(customQuestionnaire)) { |
| 105 | + if (is.null(custom_questionnaire)) { |
112 | 106 | message("Custom Questionnaire not given. Using package default Questionnaire...") |
113 | 107 | responses <- create_default_questionnaire() |
114 | | - |
115 | 108 | } else { |
116 | | - if (class(customQuestionnaire) != "BdQuestionContainer") { |
| 109 | + if (class(custom_questionnaire) != "BdQuestionContainer") { |
117 | 110 | message( |
118 | 111 | "Provided Custom Questionnaire is not of class BdQuestionContainer. |
119 | 112 | Using package default Questionnaire" |
120 | 113 | ) |
121 | 114 | responses <- create_default_questionnaire() |
122 | | - |
123 | 115 | } else { |
124 | 116 | message("Custom Questionnaire detected.") |
125 | | - responses <- customQuestionnaire |
| 117 | + responses <- custom_questionnaire |
126 | 118 | } |
127 | 119 | } |
128 | | - |
129 | 120 | message("Please answer the following questions to initiate cleaning process.") |
130 | | - |
131 | | - for (question in responses$BdQuestions) { |
| 121 | + for (question in responses$bdquestions) { |
132 | 122 | if (question$question.type != "Child" && |
133 | 123 | question$question.type != "ChildRouter") { |
134 | | - getUserResponse(question) |
| 124 | + get_user_response(question) |
135 | 125 | } |
136 | 126 | } |
137 | 127 | message("Thank you! Cleaning can be started now based on your responses.") |
138 | 128 | return(responses) |
139 | 129 | } |
140 | 130 |
|
141 | 131 | #' Internal function for getting user response |
| 132 | +#' |
| 133 | +#' @param bd_question The BDQuestion object to get users responses. |
| 134 | +#' |
| 135 | +#' @examples |
142 | 136 | #' |
143 | | -#'@param bdQuestion The BDQuestion object to get users responses. |
| 137 | +#' if(interactive()){ |
| 138 | +#' |
| 139 | +#' question <- BdQuestion() |
| 140 | +#' responses <- get_user_response(question) |
144 | 141 | #' |
145 | | -getUserResponse <- function(bdQuestion) { |
| 142 | +#' } |
| 143 | +get_user_response <- function(bd_question) { |
146 | 144 | # Child & ChildRouter already filtered in first loop above |
147 | | - |
148 | | - if (bdQuestion$question.type == "Atomic") { |
| 145 | + if (bd_question$question.type == "Atomic") { |
149 | 146 | # Atomic is filtered |
150 | | - bdQuestion$printQuestion() |
151 | | - bdQuestion$getResponse() |
152 | | - |
| 147 | + bd_question$print_question() |
| 148 | + bd_question$get_response() |
153 | 149 | } else { |
154 | 150 | # Router , Child as child & ChildRouter as child is filtered |
155 | | - bdQuestion$printQuestion() |
156 | | - bdQuestion$getResponse() |
157 | | - if (bdQuestion$users.answer %in% bdQuestion$router.condition) { |
158 | | - for (question in bdQuestion$child.questions) { |
159 | | - getUserResponse(question) |
| 151 | + bd_question$print_question() |
| 152 | + bd_question$get_response() |
| 153 | + if (bd_question$users.answer %in% bd_question$router.condition) { |
| 154 | + for (question in bd_question$child.questions) { |
| 155 | + get_user_response(question) |
160 | 156 | } |
161 | 157 | } |
162 | 158 | } |
|
0 commit comments