trevorld / r-argparse
Showing 1 of 5 files from the diff.
Other files ignored by Codecov
NEWS.md has changed.
.Rbuildignore has changed.
DESCRIPTION has changed.

@@ -217,12 +217,14 @@
Loading
217 217
}
218 218
219 219
# @param argument argument to be converted from R to Python
220 -
convert_argument <- function(argument) {
220 +
convert_argument <- function(argument, as_list = FALSE) {
221 221
    if (is.character(argument)) argument <- shQuote(argument, type = "sh")
222 222
    if (is.numeric(argument)) argument <- as.character(argument)
223 223
    if (is.logical(argument)) argument <- ifelse(argument, "True", "False")
224 224
    if (is.null(argument)) argument <- "None"
225 -
    if (length(argument) > 1) {
225 +
    if (as_list) {
226 +
        argument <- sprintf("[%s]", paste(argument, collapse = ", "))
227 +
    } else if (length(argument) > 1) {
226 228
        argument <- sprintf("(%s)", paste(argument, collapse = ", "))
227 229
    }
228 230
    argument
@@ -243,6 +245,17 @@
Loading
243 245
    sprintf("type=%s", python_type)
244 246
}
245 247
248 +
should_as_list <- function(name, argument_list) {
249 +
    if (name == "default" &&
250 +
        (argument_list[["action"]] %||% "store") == "append") {
251 +
        TRUE
252 +
    } else {
253 +
        FALSE
254 +
    }
255 +
}
256 +
257 +
`%||%` <- function(x, y) if (is.null(x)) y else x # nolint
258 +
246 259
# @param mode Either "add_argument" or "ArgumentParser"
247 260
convert_..._to_arguments <- function(mode, ...) { # nolint
248 261
@@ -255,7 +268,8 @@
Loading
255 268
    for (ii in seq_along(argument_list)) {
256 269
        name <- argument_names[ii]
257 270
        equal <- equals[ii]
258 -
        argument <- convert_argument(argument_list[[ii]])
271 +
        as_list <- should_as_list(name, argument_list)
272 +
        argument <- convert_argument(argument_list[[ii]], as_list)
259 273
        proposed_arguments <- append(proposed_arguments,
260 274
                                     paste0(name, equal, argument))
261 275
    }
Files Coverage
R/argparse.R 93.02%
Project Totals (1 files) 93.02%
Untitled

No yaml found.

Create your codecov.yml to customize your Codecov experience

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