Skip to content

Commit f666b14

Browse files
author
Jordan S Read
committed
Merge pull request #257 from jread-usgs/master
for accessors to xlim and par
2 parents c9a8d30 + d5edefe commit f666b14

File tree

11 files changed

+212
-2
lines changed

11 files changed

+212
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: gsplot
22
Type: Package
33
Title: Geological Survey Plotting
4-
Version: 0.4.0
4+
Version: 0.4.1
55
Date: 2015-09-16
66
Authors@R: c( person("Jordan", "Read", role = "aut",
77
email = "[email protected]"),

NAMESPACE

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

33
S3method(gsplot,default)
4+
S3method(logged,gsplot)
45
S3method(print,gsplot)
6+
S3method(xlim,gsplot)
7+
S3method(ylim,gsplot)
58
export("%>%")
69
export(abline)
710
export(arrows)
@@ -19,6 +22,7 @@ export(is.gsplot)
1922
export(legend)
2023
export(lines)
2124
export(loadConfig)
25+
export(logged)
2226
export(mtext)
2327
export(par)
2428
export(points)
@@ -28,6 +32,8 @@ export(segments)
2832
export(symbols)
2933
export(text)
3034
export(title)
35+
export(xlim)
36+
export(ylim)
3137
exportMethods(gsplot)
3238
importFrom(graphics,box)
3339
importFrom(graphics,mtext)

R/access-gsplot.R

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
3+
#' xlim for gsplot
4+
#'
5+
#' get the xlim for views in gsplot object
6+
#'
7+
#' @param object a gsplot object
8+
#' @param side which side(s) to use
9+
#'
10+
#' @export
11+
xlim <- function(object, side) UseMethod("xlim")
12+
13+
#' @export
14+
xlim.gsplot <- function(object, side=NULL){
15+
16+
if (!is.null(side))
17+
views <- object[views_with_side(views(object), side)]
18+
else
19+
views <- views(object)
20+
names = unname(sapply(views, function(x) paste0('side.',x$window$side[1])))
21+
unique(lapply(views, function(x) x$window$xlim)) %>%
22+
setNames(unique(names))
23+
}
24+
25+
#' ylim for gsplot
26+
#'
27+
#' get the ylim for views in gsplot object
28+
#'
29+
#' @param object a gsplot object
30+
#' @param side which side(s) to use
31+
#'
32+
#' @export
33+
ylim <- function(object, side) UseMethod("ylim")
34+
35+
#' @export
36+
ylim.gsplot <- function(object, side=NULL){
37+
if (!is.null(side))
38+
views <- object[views_with_side(views(object), side)]
39+
else
40+
views <- views(object)
41+
names = unname(sapply(views, function(x) paste0('side.',x$window$side[2])))
42+
unique(lapply(views, function(x) x$window$ylim)) %>%
43+
setNames(unique(names))
44+
}
45+
46+
#' log for gsplot
47+
#'
48+
#' get the log for views in gsplot object
49+
#'
50+
#' @name logged
51+
#' @param object a gsplot object
52+
#' @param side which side(s) to use (returns logical)
53+
#' @export
54+
logged <- function(object, side) UseMethod('logged')
55+
56+
#' @rdname logged
57+
#' @export
58+
logged.gsplot <- function(object, side=NULL){
59+
60+
is.logged <- function(window, side){
61+
log = window$log
62+
if (side %% 2 == 0){ # is y
63+
grepl(pattern = 'y',log)
64+
} else {
65+
grepl(pattern = 'x',log)
66+
}
67+
}
68+
if (!is.null(side)){
69+
sapply(side, function(x) is.logged(object[[views_with_side(views(object), side=x)[1]]]$window, x))
70+
} else {
71+
names = unname(sapply(views(object), function(x) paste0('side.',paste(x$window$side[1:2],collapse='.'))))
72+
lapply(views(object), function(x) x$window$log) %>%
73+
setNames(names)
74+
}
75+
}

R/override.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#' @importFrom utils getFromNamespace
22
#' @importFrom stats setNames
33
#' @importFrom methods existsFunction
4+
45
override <- function(package, name, object, ...) {
56
if(!missing(object) && class(object) == "gsplot") {
67
fun <- function(object, ...) {

R/par.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ par <- function(object, ...) {
2727

2828

2929
par.gsplot <- function(object, ...){
30-
current_list <- config("par")
3130
arguments <- list(...)
31+
32+
if (length(arguments)==0 && !is.null(object$par))
33+
return(object$par)
34+
current_list <- config("par")
35+
3236

3337
# // only add config list items if they aren't in ..., and aren't already set in par (i.e., don't reset them)
3438
indicesToAdd <- !(names(current_list) %in% names(arguments)) & !(names(current_list) %in% names(object[['par']]))
97 Bytes
Loading
-1.83 KB
Loading

man/logged.Rd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/access-gsplot.R
3+
\name{logged}
4+
\alias{logged}
5+
\alias{logged.gsplot}
6+
\title{log for gsplot}
7+
\usage{
8+
logged(object, side)
9+
10+
\method{logged}{gsplot}(object, side = NULL)
11+
}
12+
\arguments{
13+
\item{object}{a gsplot object}
14+
15+
\item{side}{which side(s) to use (returns logical)}
16+
}
17+
\description{
18+
get the log for views in gsplot object
19+
}
20+

man/xlim.Rd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/access-gsplot.R
3+
\name{xlim}
4+
\alias{xlim}
5+
\title{xlim for gsplot}
6+
\usage{
7+
xlim(object, side)
8+
}
9+
\arguments{
10+
\item{object}{a gsplot object}
11+
12+
\item{side}{which side(s) to use}
13+
}
14+
\description{
15+
get the xlim for views in gsplot object
16+
}
17+

man/ylim.Rd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/access-gsplot.R
3+
\name{ylim}
4+
\alias{ylim}
5+
\title{ylim for gsplot}
6+
\usage{
7+
ylim(object, side)
8+
}
9+
\arguments{
10+
\item{object}{a gsplot object}
11+
12+
\item{side}{which side(s) to use}
13+
}
14+
\description{
15+
get the ylim for views in gsplot object
16+
}
17+

0 commit comments

Comments
 (0)