ARawles / BMRSr

@@ -0,0 +1,9 @@
Loading
1 +
as_parameter <- function(parameter) {
2 +
  param <- list(
3 +
    argument_name = parameter,
4 +
    url_name = get_url_parameter_name(parameter),
5 +
    clean_function = get_clean_function(parameter)
6 +
  )
7 +
  class(param) <- "parameter"
8 +
  param
9 +
}

@@ -0,0 +1,11 @@
Loading
1 +
as_data_item <- function(data_item) {
2 +
  di <- list(
3 +
    name = data_item,
4 +
    type = get_data_item_type(data_item),
5 +
    params = get_parameters(data_item)
6 +
  )
7 +
8 +
  class(di) <- "data_item"
9 +
  di
10 +
}
11 +

@@ -41,7 +41,7 @@
Loading
41 41
#' get_parameters("TEMP")
42 42
#' @export
43 43
get_parameters <- function(data_item){
44 -
  return(get_parameters_list[[upper_case(data_item)]])
44 +
  get_parameters_list[[upper_case(data_item)]]
45 45
}
46 46
47 47
@@ -71,7 +71,7 @@
Loading
71 71
  else {
72 72
    stop("type parameter is not valid")
73 73
  }
74 -
  return(ret)
74 +
  ret
75 75
}
76 76
77 77
#' Get a vector containing all of the permissible data items
@@ -91,7 +91,7 @@
Loading
91 91
    }
92 92
93 93
  }
94 -
  return(ret)
94 +
  ret
95 95
}
96 96
97 97
#' Get the column names for a returned CSV Legacy dataset
@@ -105,7 +105,7 @@
Loading
105 105
    stop("Not a valid Legacy data item")
106 106
  }
107 107
108 -
  return(get_column_names_list[[data_item]])
108 +
  get_column_names_list[[data_item]]
109 109
}
110 110
111 111
#' Reformat date, time, and datetime columns
@@ -132,3 +132,38 @@
Loading
132 132
  return(x)
133 133
}
134 134
135 +
136 +
#' Convert a parameter name to a different format
137 +
#'
138 +
#' The names of the parameters that are used in the R functions do not perfectly correspond with the parameter name expected by the API. This
139 +
#' function converts an argument parameter name (e.g. `settlement_date`) to the URL argument name (e.g. `SettlementDate`) or the other way around
140 +
#' @param parameter character; name of the parameter provided to the relevant `build()` function
141 +
#' @param from character; one of "argument" or "url" depending on whether `parameter` is in the argument or URL format
142 +
#' @param to character; one of "argument" or "url"
143 +
#' @return character; name of the parameter used in the URL request or `build()` function. If no match is found, `character(0)`
144 +
#' @export
145 +
change_parameter_name <- function(parameter, from = c("argument", "url"), to = c("url", "argument")) {
146 +
  from <- match.arg(from)
147 +
  to <- match.arg(to)
148 +
  from_col <- rlang::sym(paste0(from, "_name"))
149 +
  to_col <- rlang::sym(paste0(to, "_name"))
150 +
  results <- dplyr::filter(parameter_name_map,  {{ from_col }} == parameter)
151 +
  dplyr::pull(results, {{ to_col }})
152 +
}
153 +
154 +
#' Get the cleaning function required for a parameter
155 +
#'
156 +
#' Before a parameter can be added to a request, it often needs to be cleaned. This function returns the appropriate function for a parameter.
157 +
#' Parameters can be supplied with their name used in the `build()` functions ("argument") or in the URL
158 +
#' @param character; name of the parameter. Either the parameter as it's passed to the `build()` functions or the name of the parameter in the URL
159 +
#' depending on the value of `format`
160 +
#' @param format character; what format is `parameter` in? One of "argument" (default) or "url"
161 +
#' @return character; name of the cleaning function
162 +
#' @export
163 +
get_cleaning_function <- function(parameter, format = c("argument", "url")) {
164 +
  format <- match.arg(format)
165 +
  if (format == "url") {
166 +
    parameter <- change_parameter_name(parameter, from = "url", to = "argument")
167 +
  }
168 +
  dplyr::filter(parameter_clean_functions_map, name == parameter)[["function"]]
169 +
}

@@ -244,9 +244,9 @@
Loading
244 244
#' Default is TRUE.
245 245
#' @param ... values to be passed to appropriate build_x_call function
246 246
#' @family call-building functions
247 -
#' @seealso \code{\link{build_b_call}}
248 -
#' @seealso \code{\link{build_remit_call}}
249 -
#' @seealso \code{\link{build_legacy_call}}
247 +
#' @seealso [build_b_call()]
248 +
#' @seealso [build_remit_call()]
249 +
#' @seealso [build_legacy_call()]
250 250
#' @examples
251 251
#' build_call(data_item = "TEMP", api_key = "12345", from_date = "12 Jun 2018",
252 252
#' to_date = "13 Jun 2018", service_type = "csv")

@@ -72,7 +72,7 @@
Loading
72 72
#' Parse a .csv response with a EOF tag left in
73 73
#'
74 74
#' Some .csv files returned from the API still have an EOF tag left at the bottom and contain 4 lines of nonsense.
75 -
#' This function is used to parse these files, whereas the \code{parse_clean_csv()} function is used to
75 +
#' This function is used to parse these files, whereas the `parse_clean_csv()` function is used to
76 76
#' parse .csv files without this tag and the junk lines.
77 77
#' @param content character; the original response object parsed as a single text string.
78 78
#' @return tibble; a tibble containing the data in the .csv file
@@ -92,7 +92,7 @@
Loading
92 92
#' Parse a 'clean' .csv response
93 93
#'
94 94
#' Some .csv files are returned without the EOF tag and with only 1 line before the data. This
95 -
#' function is used to parse these files, whereas the \code{parse_eof_csv()} function is used
95 +
#' function is used to parse these files, whereas the `parse_eof_csv()` function is used
96 96
#' to parse those files with the EOF tag and junk lines.
97 97
#' @param content character; the original response object parsed as a single text string.
98 98
#' @return tibble; a tibble containing the data in the .csv file
@@ -111,7 +111,7 @@
Loading
111 111
#' This simple wrapper returns an empty tibble on error and returns a custom warning message.
112 112
#' @param expr expression; expression to be evaluated for errors
113 113
#' @param error_message character; character string to be displayed as a warning on error
114 -
#' @param ... extra parameters to be passed to the \code{tryCatch()} function.
114 +
#' @param ... extra parameters to be passed to the `tryCatch()` function.
115 115
#' @return evaluated expression on success or empty tibble on error
116 116
try_parse <- function(expr, error_message, ...) {
117 117
  tryCatch({
Files Coverage
R 78.31%
Project Totals (8 files) 78.31%
1
comment: false
2

3

4
coverage:
5
  status:
6
    project:
7
      default:
8
        target: auto
9
        threshold: 1%
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading