diff --git a/NAMESPACE b/NAMESPACE index 8477475..c200f48 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -46,6 +46,8 @@ export(text) export(title) export(view) export(view_info) +export(whatDate) +export(whatVersion) export(xlab) export(xlim) export(ylab) diff --git a/R/access-gsplot.R b/R/access-gsplot.R index f3ddc2b..5996a56 100644 --- a/R/access-gsplot.R +++ b/R/access-gsplot.R @@ -258,4 +258,28 @@ view_info <- function(object){ viewInfo$y.side.defined.by.user <- viewInfo$y %in% defined.sides return(viewInfo) -} \ No newline at end of file +} + +#' Get gsplot object creation date. +#' +#' Get the date that this gsplot object was originally created. +#' +#' @param object a gsplot object +#' @return The date the gsplot object was created. +#' @export +whatDate <- function(object){ + date_created <- object$metadata$created + return(date_created) +} + +#' Get gsplot version used. +#' +#' Get the version number that was used to create this gsplot object. +#' +#' @param object a gsplot object +#' @return The gsplot version number. +#' @export +whatVersion <- function(object){ + version_created <- object$metadata$gsplot.version + return(version_created) +} diff --git a/R/gsplot-class.R b/R/gsplot-class.R index add8a18..9dc6810 100644 --- a/R/gsplot-class.R +++ b/R/gsplot-class.R @@ -3,6 +3,10 @@ #' Used to change the class of inputs to "gsplot". #' #' @param x list +#' @param created vector of length one giving the date the gsplot object was created. Defaults to +#' using \code{Sys.Date()}. Output class matches that of the input. +#' @param gsplot.version vector of length one giving the version of the gsplot package used to create the +#' object. Defaults to calling \code{packageDescription()}. Output class matches that of the input. #' @param config.file path to the file that will only be used for setting #' par in this one gsplot object. If \code{NA} (default), par is set by the global options set by #' loadConfig(). @@ -19,8 +23,13 @@ gsplot <- function(x = NULL, ...) UseMethod("gsplot") #' @rdname gsplot #' @export -gsplot.default <- function(...,config.file=NA, theme=NA, frame.plot=TRUE) { - object <- gsplot(list(global=list('config'=list(frame.plot=frame.plot, +gsplot.default <- function(..., created=Sys.Date(), + gsplot.version=packageDescription(getPackageName(), + fields = "Version"), + config.file=NA, theme=NA, frame.plot=TRUE) { + object <- gsplot(list(metadata=list(created=created, + gsplot.version=gsplot.version), + global=list('config'=list(frame.plot=frame.plot, config.file=!is.na(config.file), theme=!is.na(theme))))) diff --git a/man/gsplot.Rd b/man/gsplot.Rd index d5ceed7..cc94069 100644 --- a/man/gsplot.Rd +++ b/man/gsplot.Rd @@ -8,14 +8,21 @@ \usage{ gsplot(x = NULL, ...) -\method{gsplot}{default}(..., config.file = NA, theme = NA, - frame.plot = TRUE) +\method{gsplot}{default}(..., created = Sys.Date(), + gsplot.version = packageDescription("gsplot", fields = "Version"), + config.file = NA, theme = NA, frame.plot = TRUE) \method{gsplot}{list}(x) } \arguments{ \item{x}{list} +\item{created}{vector of length one giving the date the gsplot object was created. Defaults to +using \code{Sys.Date()}. Output class matches that of the input.} + +\item{gsplot.version}{vector of length one giving the version of the gsplot package used to create the +object. Defaults to calling \code{packageDescription()}. Output class matches that of the input.} + \item{config.file}{path to the file that will only be used for setting par in this one gsplot object. If \code{NA} (default), par is set by the global options set by loadConfig().} diff --git a/man/whatDate.Rd b/man/whatDate.Rd new file mode 100644 index 0000000..38c0988 --- /dev/null +++ b/man/whatDate.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/access-gsplot.R +\name{whatDate} +\alias{whatDate} +\title{Get gsplot object creation date.} +\usage{ +whatDate(object) +} +\arguments{ +\item{object}{a gsplot object} +} +\value{ +The date the gsplot object was created. +} +\description{ +Get the date that this gsplot object was originally created. +} + diff --git a/man/whatVersion.Rd b/man/whatVersion.Rd new file mode 100644 index 0000000..ab01de7 --- /dev/null +++ b/man/whatVersion.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/access-gsplot.R +\name{whatVersion} +\alias{whatVersion} +\title{Get gsplot version used.} +\usage{ +whatVersion(object) +} +\arguments{ +\item{object}{a gsplot object} +} +\value{ +The gsplot version number. +} +\description{ +Get the version number that was used to create this gsplot object. +} + diff --git a/tests/testthat/test-access_gsplot.R b/tests/testthat/test-access_gsplot.R index 463006b..9147c94 100644 --- a/tests/testthat/test-access_gsplot.R +++ b/tests/testthat/test-access_gsplot.R @@ -141,3 +141,16 @@ test_that("summary ",{ points(x=3:10,y=4:11, side=c(1,2), log='xy') expect_output(summary(usrDef),regexp = "2 views:") }) + +test_that("users can access metadata", { + gs <- gsplot() + expect_equal(whatDate(gs), Sys.Date()) + + old.version <- "0.5.2" + gs2 <- gsplot(gsplot.version=old.version) + expect_equal(whatVersion(gs2), old.version) + + old.date <- as.Date("2010-10-21") + gs3 <- gsplot(created=old.date) + expect_equal(whatDate(gs3), old.date) +}) diff --git a/tests/testthat/tests-axis.R b/tests/testthat/tests-axis.R index 984e07a..7ac0729 100644 --- a/tests/testthat/tests-axis.R +++ b/tests/testthat/tests-axis.R @@ -14,7 +14,8 @@ test_that("axis",{ test_that("axis gsplot",{ gs = points(gsplot(mar=c(1,1,1,1)), c(-2,3), c(-1,5)) %>% axis(3) - expect_true(all(names(gs) %in% c("side.1", "side.2", "side.3", "view.1.2", "global"))) + expect_true(all(names(gs) %in% c("side.1", "side.2", "side.3", + "view.1.2", "global", "metadata"))) gs <- gsplot() %>% lines(1:5, c(1,10,100,1000,10000), log="y", axes=FALSE) %>%