Skip to content

Commit 98e3e0a

Browse files
author
Jordan S Read
authored
Merge pull request #421 from lindsaycarr/addMetadata
Add metadata
2 parents e839398 + 2327280 commit 98e3e0a

File tree

8 files changed

+98
-6
lines changed

8 files changed

+98
-6
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export(text)
4646
export(title)
4747
export(view)
4848
export(view_info)
49+
export(whatDate)
50+
export(whatVersion)
4951
export(xlab)
5052
export(xlim)
5153
export(ylab)

R/access-gsplot.R

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,28 @@ view_info <- function(object){
258258
viewInfo$y.side.defined.by.user <- viewInfo$y %in% defined.sides
259259

260260
return(viewInfo)
261-
}
261+
}
262+
263+
#' Get gsplot object creation date.
264+
#'
265+
#' Get the date that this gsplot object was originally created.
266+
#'
267+
#' @param object a gsplot object
268+
#' @return The date the gsplot object was created.
269+
#' @export
270+
whatDate <- function(object){
271+
date_created <- object$metadata$created
272+
return(date_created)
273+
}
274+
275+
#' Get gsplot version used.
276+
#'
277+
#' Get the version number that was used to create this gsplot object.
278+
#'
279+
#' @param object a gsplot object
280+
#' @return The gsplot version number.
281+
#' @export
282+
whatVersion <- function(object){
283+
version_created <- object$metadata$gsplot.version
284+
return(version_created)
285+
}

R/gsplot-class.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#' Used to change the class of inputs to "gsplot".
44
#'
55
#' @param x list
6+
#' @param created vector of length one giving the date the gsplot object was created. Defaults to
7+
#' using \code{Sys.Date()}. Output class matches that of the input.
8+
#' @param gsplot.version vector of length one giving the version of the gsplot package used to create the
9+
#' object. Defaults to calling \code{packageDescription()}. Output class matches that of the input.
610
#' @param config.file path to the file that will only be used for setting
711
#' par in this one gsplot object. If \code{NA} (default), par is set by the global options set by
812
#' loadConfig().
@@ -19,8 +23,13 @@ gsplot <- function(x = NULL, ...) UseMethod("gsplot")
1923

2024
#' @rdname gsplot
2125
#' @export
22-
gsplot.default <- function(...,config.file=NA, theme=NA, frame.plot=TRUE) {
23-
object <- gsplot(list(global=list('config'=list(frame.plot=frame.plot,
26+
gsplot.default <- function(..., created=Sys.Date(),
27+
gsplot.version=packageDescription(getPackageName(),
28+
fields = "Version"),
29+
config.file=NA, theme=NA, frame.plot=TRUE) {
30+
object <- gsplot(list(metadata=list(created=created,
31+
gsplot.version=gsplot.version),
32+
global=list('config'=list(frame.plot=frame.plot,
2433
config.file=!is.na(config.file),
2534
theme=!is.na(theme)))))
2635

man/gsplot.Rd

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/whatDate.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/whatVersion.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-access_gsplot.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,16 @@ test_that("summary ",{
141141
points(x=3:10,y=4:11, side=c(1,2), log='xy')
142142
expect_output(summary(usrDef),regexp = "2 views:")
143143
})
144+
145+
test_that("users can access metadata", {
146+
gs <- gsplot()
147+
expect_equal(whatDate(gs), Sys.Date())
148+
149+
old.version <- "0.5.2"
150+
gs2 <- gsplot(gsplot.version=old.version)
151+
expect_equal(whatVersion(gs2), old.version)
152+
153+
old.date <- as.Date("2010-10-21")
154+
gs3 <- gsplot(created=old.date)
155+
expect_equal(whatDate(gs3), old.date)
156+
})

tests/testthat/tests-axis.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ test_that("axis",{
1414
test_that("axis gsplot",{
1515
gs = points(gsplot(mar=c(1,1,1,1)), c(-2,3), c(-1,5)) %>%
1616
axis(3)
17-
expect_true(all(names(gs) %in% c("side.1", "side.2", "side.3", "view.1.2", "global")))
17+
expect_true(all(names(gs) %in% c("side.1", "side.2", "side.3",
18+
"view.1.2", "global", "metadata")))
1819

1920
gs <- gsplot() %>%
2021
lines(1:5, c(1,10,100,1000,10000), log="y", axes=FALSE) %>%

0 commit comments

Comments
 (0)