Skip to content

Commit 93aefac

Browse files
author
Jordan S Read
committed
logged w/ sides=c(1,2) args (optional) #246
1 parent 2eda248 commit 93aefac

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Generated by roxygen2 (4.1.1): do not edit by hand
22

33
S3method(gsplot,default)
4-
S3method(log,gsplot)
4+
S3method(logged,gsplot)
55
S3method(print,gsplot)
66
S3method(xlim,gsplot)
77
S3method(ylim,gsplot)
@@ -22,7 +22,7 @@ export(is.gsplot)
2222
export(legend)
2323
export(lines)
2424
export(loadConfig)
25-
export(log)
25+
export(logged)
2626
export(mtext)
2727
export(par)
2828
export(points)

R/access-gsplot.R

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,29 @@ ylim.gsplot <- function(object){
3838
#'
3939
#' get the log for views in gsplot object
4040
#'
41-
#' @aliases log
42-
#' @name log
43-
#' @rdname log
41+
#' @name logged
4442
#' @param object a gsplot object
4543
#' @param side which side(s) to use (returns logical)
4644
#' @export
47-
log <- function(object, side) {
48-
if (is.gsplot(object))
49-
UseMethod('log')
50-
base::log(x=object, base=side)
51-
}
45+
logged <- function(object, side) UseMethod('logged')
5246

47+
#' @rdname logged
5348
#' @export
54-
log.gsplot <- function(x, side=NULL){
55-
names = unname(sapply(views(x), function(x) paste0('side.',paste(x$window$side[1:2],collapse='.'))))
56-
logs = lapply(views(x), function(x) x$window$log) %>%
57-
setNames(names)
49+
logged.gsplot <- function(object, side=NULL){
5850

51+
is.logged <- function(window, side){
52+
log = window$log
53+
if (side %% 2 == 0){ # is y
54+
grepl(pattern = 'y',log)
55+
} else {
56+
grepl(pattern = 'x',log)
57+
}
58+
}
5959
if (!is.null(side)){
60-
warning('not yet implemented. Will return boolean for side matches')
60+
sapply(side, function(x) is.logged(object[[views_with_side(views(object), side=x)[1]]]$window, x))
61+
} else {
62+
names = unname(sapply(views(object), function(x) paste0('side.',paste(x$window$side[1:2],collapse='.'))))
63+
lapply(views(object), function(x) x$window$log) %>%
64+
setNames(names)
6165
}
62-
return(logs)
6366
}

man/log.Rd renamed to man/logged.Rd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/access-gsplot.R
3-
\name{log}
4-
\alias{log}
3+
\name{logged}
4+
\alias{logged}
5+
\alias{logged.gsplot}
56
\title{log for gsplot}
67
\usage{
7-
log(object, side)
8+
logged(object, side)
9+
10+
\method{logged}{gsplot}(object, side = NULL)
811
}
912
\arguments{
1013
\item{object}{a gsplot object}

tests/testthat/test-access_gsplot.R

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,29 @@ test_that("par for simple object",{
4141
expect_is(par(gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r')), 'list')
4242
})
4343

44-
context("test get log for gsplot object")
44+
context("test get logged for gsplot object")
4545

46-
test_that("log for simple object",{
46+
test_that("logged for simple object",{
4747
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
4848
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat') %>%
4949
points(x=3:10,y=4:11, side=c(1,2))
50-
expect_equal(log(usrDef)[[1]],"")
51-
expect_equal(log(usrDef)[[2]],"")
50+
expect_equal(logged(usrDef)[[1]],"")
51+
expect_equal(logged(usrDef)[[2]],"")
5252

5353
usrDef <- lines(usrDef,1:2,4:5, log='xy')
54-
expect_equal(log(usrDef)[[1]],"")
55-
expect_equal(log(usrDef)[[2]],"xy")
54+
expect_equal(logged(usrDef)[[1]],"")
55+
expect_equal(logged(usrDef)[[2]],"xy")
5656

5757
})
5858

59-
test_that("base::log still works as expected",{
60-
expect_equal(log(10),base::log(10))
61-
})
59+
test_that("logged side extractor ",{
60+
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
61+
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat',log='y') %>%
62+
points(x=3:10,y=4:11, side=c(1,2), log='xy')
63+
expect_true(logged(usrDef, side=1))
64+
expect_false(logged(usrDef, side=3))
65+
66+
dual = logged(usrDef, side=c(1,2))
67+
expect_equal(length(dual), 2)
68+
expect_true(all(dual))
69+
})

0 commit comments

Comments
 (0)