R/ExperimentHub-option.R

Defines functions setExperimentHubOption getExperimentHubOption

Documented in getExperimentHubOption setExperimentHubOption

.EH_hub_options <- new.env(parent=emptyenv())

getExperimentHubOption <- function(arg) {
    stopifnot(is.character(arg), length(arg) == 1L)
    arg <- toupper(arg)
    key <- c("URL", "CACHE", "PROXY", "MAX_DOWNLOADS")
    if (!arg %in% key)
        stop(paste0("'arg' must be one of 'URL', 'CACHE', 'PROXY', ",
             "or 'MAXDOWNLOADS'"))
    .EH_hub_options[[arg]]
}

setExperimentHubOption <- function(arg, value)
{
    stopifnot(is.character(arg), length(arg) == 1L)
    key <- .hub_option_key(toupper(trimws(arg)))

    .EH_hub_options[[key]] <- switch(key, URL=, CACHE={
        value <- as.character(value)
        stopifnot(isSingleString(value))
        value
    }, MAX_DOWNLOADS={
        value <- as.integer(value)
        stopifnot(isSingleInteger(value))
        value
    }, PROXY={
        if (is.null(value) || inherits(value, "request"))
            value
        else if (isSingleString(value)) {
            .httr_proxy(value)
        } else {
            txt <- "'value' must be an httr proxy request (use_proxy()),
                    character(1), or NULL"
            stop(paste(strwrap(txt, exdent=2), collapse="\n"))
        }
    })
}

Try the ExperimentHub package in your browser

Any scripts or data that you put into this service are public.

ExperimentHub documentation built on Nov. 17, 2017, 11:07 a.m.