From c8c8087fa53b422a6be9ffcfa2882d1614093cff Mon Sep 17 00:00:00 2001 From: katieb1 Date: Thu, 18 Apr 2024 16:18:35 -0700 Subject: [PATCH] Changed chartLine to chartData; can now set type --- DESCRIPTION | 2 +- NAMESPACE | 2 +- R/{chartLine.R => chartData.R} | 38 +++++++++++++++++------------- man/{chartLine.Rd => chartData.Rd} | 38 +++++++++++++++++------------- 4 files changed, 45 insertions(+), 35 deletions(-) rename R/{chartLine.R => chartData.R} (82%) rename man/{chartLine.Rd => chartData.Rd} (60%) diff --git a/DESCRIPTION b/DESCRIPTION index 340a918e..3db36c8b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -51,8 +51,8 @@ Collate: 'autogentags.R' 'backup.R' 'chart.R' + 'chartData.R' 'chartId.R' - 'chartLine.R' 'command.R' 'condaFilepath.R' 'createCondaEnv.R' diff --git a/NAMESPACE b/NAMESPACE index 3f9dbd55..65ff8681 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,8 +24,8 @@ export(addRow) export(autogentags) export(backup) export(chart) +export(chartData) export(chartId) -export(chartLine) export(command) export(condaFilepath) export(createCondaEnv) diff --git a/R/chartLine.R b/R/chartData.R similarity index 82% rename from R/chartLine.R rename to R/chartData.R index b546d6ab..ec005f74 100644 --- a/R/chartLine.R +++ b/R/chartData.R @@ -8,15 +8,16 @@ NULL #' Sets the \code{\link{Chart}} type to "Line" and adds the variables to plot #' in the line chart. #' -#' @param Chart \code{\link{Chart}} object -#' @param x character or character vector. X variable(s) to plot (Default is -#' "Timesteps"). +#' @param chart \code{\link{Chart}} object +#' @param type character. Chart type. Can be "Line" (Default) or "Column". +#' @param x character or character vector. X variable(s) to plot. If \code{NULL} +#' (Default), then will plot timesteps along the X axis. #' @param y character or character vector. Y variable(s) to plot. #' @param timesteps integer vector. The range of timesteps to plot against #' (Default is the minimum and maximum timesteps defined in the simulation). #' @param iterationType character. How to display multiple iterations in the -#' chart. Can be "mean" (Default), "single", or "all". -#' @param iteration integer. If the `iterationType` is set to "single", this argument +#' chart. Can be "Mean" (Default), "Single", or "All". +#' @param iteration integer. If the `iterationType` is set to "Single", this argument #' determines which iteration to display. Default is 1. #' #' @return @@ -28,19 +29,19 @@ NULL #' myChart <- chart(myProject, chart = "New Chart") #' #' # Set the chart type and data -#' myChart <- chartLine(myChart, x = "Timesteps", y = c("variable1", "variable2"), +#' myChart <- chartData(myChart, y = c("variable1", "variable2"), #' timesteps = c(0,10), iterationType = "single", iteration = 1) #' #' } #' #' @export -setGeneric("chartLine", function(chart, x = "Timesteps", y = NULL, - timesteps = NULL, iterationType = "mean", - iteration = 1) standardGeneric("chartLine")) +setGeneric("chartData", function(chart, type = "Line", x = NULL, y = NULL, + timesteps = NULL, iterationType = "Mean", + iteration = 1) standardGeneric("chartData")) -#' @rdname chartLine -setMethod("chartLine", signature(chart = "Chart"), - function(chart, x, y, timesteps, iterationType, iteration) { +#' @rdname chartData +setMethod("chartData", signature(chart = "Chart"), + function(chart, type, x, y, timesteps, iterationType, iteration) { # Set arguments used throughout chartSession <- .session(chart) @@ -51,11 +52,16 @@ setMethod("chartLine", signature(chart = "Chart"), generalArgs <- list(lib = libPath, pid = chartPID, cid = chartCID) # Set chart type - args <- append(list(set = NULL, `chart-type` = NULL, type = "Line"), generalArgs) + + if (!type %in% c("Line", "Column")){ + stop("type must be one of 'Line' or 'Column'.") + } + + args <- append(list(set = NULL, `chart-type` = NULL, type = type), generalArgs) tt <- command(args, session = chartSession, program = consoleExe) if (tt[1] != "saved"){ - stop("Failed to set Chart Type.") + stop(paste("Failed to set Chart Type:", tt[1])) } # Set x variable @@ -126,8 +132,8 @@ setMethod("chartLine", signature(chart = "Chart"), # Set iteration type if (!is.null(iterationType)){ - if (!iterationType %in% c("mean", "single", "all")){ - stop("iterationType must be one of 'mean', 'single', or 'all'.") + if (!iterationType %in% c("Mean", "Single", "All")){ + stop("iterationType must be one of 'Mean', 'Single', or 'All'.") } args <- append(list(set = NULL, `chart-iter-type` = NULL, `iter-type` = iterationType), generalArgs) diff --git a/man/chartLine.Rd b/man/chartData.Rd similarity index 60% rename from man/chartLine.Rd rename to man/chartData.Rd index eb1ed394..3379043b 100644 --- a/man/chartLine.Rd +++ b/man/chartData.Rd @@ -1,31 +1,37 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/chartLine.R -\name{chartLine} -\alias{chartLine} -\alias{chartLine,Chart-method} +% Please edit documentation in R/chartData.R +\name{chartData} +\alias{chartData} +\alias{chartData,Chart-method} \title{Sets the \code{\link{Chart}} type to "Line"} \usage{ -chartLine( +chartData( chart, - x = "Timesteps", + type = "Line", + x = NULL, y = NULL, timesteps = NULL, - iterationType = "mean", + iterationType = "Mean", iteration = 1 ) -\S4method{chartLine}{Chart}( +\S4method{chartData}{Chart}( chart, - x = "Timesteps", + type = "Line", + x = NULL, y = NULL, timesteps = NULL, - iterationType = "mean", + iterationType = "Mean", iteration = 1 ) } \arguments{ -\item{x}{character or character vector. X variable(s) to plot (Default is -"Timesteps").} +\item{chart}{\code{\link{Chart}} object} + +\item{type}{character. Chart type. Can be "Line" (Default) or "Column".} + +\item{x}{character or character vector. X variable(s) to plot. If \code{NULL} +(Default), then will plot timesteps along the X axis.} \item{y}{character or character vector. Y variable(s) to plot.} @@ -33,12 +39,10 @@ chartLine( (Default is the minimum and maximum timesteps defined in the simulation).} \item{iterationType}{character. How to display multiple iterations in the -chart. Can be "mean" (Default), "single", or "all".} +chart. Can be "Mean" (Default), "Single", or "All".} -\item{iteration}{integer. If the \code{iterationType} is set to "single", this argument +\item{iteration}{integer. If the \code{iterationType} is set to "Single", this argument determines which iteration to display. Default is 1.} - -\item{Chart}{\code{\link{Chart}} object} } \value{ A \code{Chart} object representing a SyncroSim chart @@ -53,7 +57,7 @@ in the line chart. myChart <- chart(myProject, chart = "New Chart") # Set the chart type and data -myChart <- chartLine(myChart, x = "Timesteps", y = c("variable1", "variable2"), +myChart <- chartData(myChart, y = c("variable1", "variable2"), timesteps = c(0,10), iterationType = "single", iteration = 1) }