diff --git a/R/chartErrorBar.R b/R/chartErrorBar.R index c7c71455..cb95becc 100644 --- a/R/chartErrorBar.R +++ b/R/chartErrorBar.R @@ -9,7 +9,7 @@ NULL #' #' @param chart \code{\link{Chart}} object #' @param type character. Type of error bar. Values can be "percentile", -#' "minmax", or "none". Default is "none". +#' "minmax", or "none". Default is NULL. #' @param lower float. If the error bar type is set to "percentile", then #' sets the minimum percentile for the lower range of the error bar. Default is #' \code{NULL}. @@ -18,7 +18,8 @@ NULL #' \code{NULL}. #' #' @return -#' A \code{Chart} object representing a SyncroSim chart +#' A \code{Chart} object representing a SyncroSim chart or a data.frame of +#' the current chart error bar settings. #' #' @examples #' \dontrun{ @@ -37,13 +38,14 @@ NULL #' } #' #' @export -setGeneric("chartErrorBar", function(chart, type = "none", lower = NULL, +setGeneric("chartErrorBar", function(chart, type = NULL, lower = NULL, upper = NULL) standardGeneric("chartErrorBar")) #' @rdname chartErrorBar setMethod("chartErrorBar", signature(chart = "Chart"), function(chart, type, lower, upper) { + browser() # Grab project and chart ID from chart proj <- .project(chart) chartCID <- .chartId(chart) @@ -53,6 +55,13 @@ setMethod("chartErrorBar", signature(chart = "Chart"), ds <- .datasheet(proj, name = chartDSName, optional = T, returnInvisible = T, includeKey = T) + if (is.null(type)){ + errorBarInfo <- data.frame(type = ds$ErrorBarType, + lower = ds$ErrorBarMinPercentile, + upper = ds$ErrorBarMaxPercentile) + return(errorBarInfo) + } + # Set error bar type if (type == "none"){ ds[ds$ChartId == chartCID,]$ErrorBarType <- "No Ranges" diff --git a/R/internalHelpers.R b/R/internalHelpers.R index 0e67529e..982bcc15 100644 --- a/R/internalHelpers.R +++ b/R/internalHelpers.R @@ -814,14 +814,15 @@ datasheets <- function(x, project = NULL, scenario = NULL, scope = NULL, refresh } # If the goal is a project, return one or more, or complain - if (!is.null(goal) && ((goal == "project") || (goal == "folder") || (goal == "chart"))) { + if (!is.null(goal) && (goal == "project")) { # if ssimObject is a scenario, return the parent project - if ((is(ssimObject, "Scenario"))) { + if (is.element(class(ssimObject), c("Scenario", "Folder", "Chart"))) { if (convertObject | !returnIds) { ssimObject <- new("Project", ssimObject, id = .projectId(ssimObject)) } } - if (is.element(class(ssimObject), c("Project", "Scenario"))) { + + if (is.element(class(ssimObject), c("Project", "Scenario", "Folder", "Chart"))) { if (returnIds) { project <- .projectId(ssimObject) if (convertObject) { @@ -1019,6 +1020,20 @@ datasheets <- function(x, project = NULL, scenario = NULL, scope = NULL, refresh return(list(ssimObject = ssimObject, project = project, scenario = scenario, scenarioSet = fullScnSet, goal = goal)) } + # if goal is chart, and we have one, return immediately + if (!is.null(goal) && (goal == "chart")) { + if (is.element(class(ssimObject), c("Chart"))) { + return(ssimObject) + } + } + + # if goal is folder, and we have one, return immediately + if (!is.null(goal) && (goal == "folder")) { + if (is.element(class(ssimObject), c("Folder"))) { + return(ssimObject) + } + } + stop(paste0("Could not identify a SsimLibrary, Project or Scenario from ssimObject, project, and scenario arguments.")) } diff --git a/R/project.R b/R/project.R index 2a1657ce..3f65c885 100644 --- a/R/project.R +++ b/R/project.R @@ -130,11 +130,11 @@ setMethod(f = "initialize", signature = "Project", definition = function(.Object #' Creates or retrieves a \code{\link{Project}} or multiple Projects from a #' SsimLibrary. #' -#' @param ssimObject \code{\link{Scenario}} or -#' \code{\link{SsimLibrary}} object, or a character string (i.e. a filepath) +#' @param ssimObject \code{\link{Scenario}}, \code{\link{SsimLibrary}}, or +#' \code{\link{Chart}} object, or a character string (i.e. a filepath) #' @param project \code{\link{Project}} object, character, integer, or vector -#' of these. Names or ids of one or more Projects. Note that integer ids are -#' slightly faster (optional) +#' of these. Names or ids of one or more Projects. Note that integer ids are +#' slightly faster (optional) #' @param sourceProject \code{\link{Project}} object, character, or integer. If #' not \code{NULL} (default), new Projects will be copies of the sourceProject #' @param summary logical. If \code{TRUE} then return the Project(s) in a data.frame with @@ -145,7 +145,7 @@ setMethod(f = "initialize", signature = "Project", definition = function(.Object #' list; otherwise returns a single project as a \code{\link{Project}} object. #' Applies only when \code{summary=FALSE} Default is \code{FALSE} #' @param overwrite logical. If \code{TRUE} an existing Project will be overwritten. -#' Default is \code{FALSE} +#' Default is \code{FALSE} #' #' @details #' For each element of project: @@ -199,6 +199,7 @@ project <- function(ssimObject = NULL, project = NULL, sourceProject = NULL, sum if ((is(ssimObject, "character")) && (is(ssimObject, SyncroSimNotFound(warn = FALSE)))) { return(SyncroSimNotFound()) } + if (is.null(ssimObject)) { e <- ssimEnvironment() ssimObject <- ssimLibrary(e$LibraryFilePath) @@ -206,7 +207,7 @@ project <- function(ssimObject = NULL, project = NULL, sourceProject = NULL, sum } # if ssimObject is a scenario or project, return the project - if (is.element(class(ssimObject), c("Scenario", "Project")) & is.null(project)) { + if (is.element(class(ssimObject), c("Scenario", "Project", "Chart")) & is.null(project)) { if (is.null(summary)) { summary <- FALSE }