diff --git a/R/prj_parameter.R b/R/prj_parameter.R index 03ed9c23999b44d010b6ee9b9521bda123ddde4c..6f3bf66a4079023fdd7c717375e342206456b43d 100644 --- a/R/prj_parameter.R +++ b/R/prj_parameter.R @@ -1,46 +1,52 @@ +#===== r2ogs6_parameter ===== + #'r2ogs6_parameter #'@description S3 class describing a .prj parameter #'@param name The parameter name #'@param type The parameter type -#'@param values Optional: The parameter values -#'@param value Optional: The parameter value +#'@param values Optional: string | numeric: Parameter values +#'@param value Optional: string | double: Parameter value #'@export -r2ogs6_parameter <- function(name, type, values = NULL, value = NULL) { +r2ogs6_parameter <- function(name, + type, + values = NULL, + value = NULL) { if(!is.null(values) && !is.null(value)){ - stop(paste("r2ogs6_parameter: Use either 'values' or 'value' parameter (XOR)"), call. = FALSE) + stop(paste("r2ogs6_parameter: Use either 'values' or 'value'", + "parameter (XOR)"), call. = FALSE) } #Coerce input - if(!is.null(value)){ - if(assertthat::is.string(value)){ - value <- as.double(value) - } - values <- value - }else{ - if(assertthat::is.string(values)){ - values <- as.double(unlist(strsplit(values, " "))) - } - } + value <- coerce_string_to_numeric(value) + values <- coerce_string_to_numeric(values, TRUE) - new_r2ogs6_parameter(name, type, values) + new_r2ogs6_parameter(name, + type, + values, + value) } -new_r2ogs6_parameter <- function(name, type, values) { +new_r2ogs6_parameter <- function(name, + type, + values, + value) { assertthat::assert_that(assertthat::is.string(name)) assertthat::assert_that(assertthat::is.string(type)) - assertthat::assert_that(is.numeric(values)) + + validate_is_null_or_numeric(values) + validate_is_null_or_number(value) structure( list( name = name, type = type, values = values, - tag_name = "parameter", + value = value, is_subclass = FALSE, attr_names = character(), flatten_on_exp = c("values") @@ -48,4 +54,3 @@ new_r2ogs6_parameter <- function(name, type, values) { class = "r2ogs6_parameter" ) } -