Skip to content

Commit 982628f

Browse files
Merge pull request #415 from USGS-R/revert-411-data_frame
Revert "Data frame"
2 parents 8a1eb23 + 4187408 commit 982628f

File tree

5 files changed

+77
-32
lines changed

5 files changed

+77
-32
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ importFrom(stats,setNames)
7373
importFrom(utils,find)
7474
importFrom(utils,getFromNamespace)
7575
importFrom(utils,getS3method)
76+
importFrom(utils,head)
7677
importFrom(utils,packageName)
7778
importFrom(utils,tail)
7879
importFrom(yaml,yaml.load_file)

R/axis.R

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ axis <- function(object, ...) {
6363
override("graphics", "axis", object, ...)
6464
}
6565

66-
axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL) {
66+
#' @importFrom utils head
67+
axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL, append=FALSE) {
6768

6869
fun.name <- "axis"
6970

@@ -76,9 +77,25 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL) {
7677

7778
for(side in sides){
7879
# append the side and give it defaults if it doesn't exist
80+
7981
object <- modify_side(object, args = list(), side=side)
82+
which.axis <- which(names(object[[as.side_name(side)]])== 'axis')
83+
if (append){
84+
last.axis <- tail(which.axis, 1) # get the last one
85+
object[[as.side_name(side)]] <- append(object[[as.side_name(side)]],
86+
list('axis' = set_args('axis', side=side, package='graphics')),
87+
after = last.axis)
88+
object[[as.side_name(side)]][[last.axis+1]] <- append_replace(object[[as.side_name(side)]][[last.axis+1]], user_args[[fun.name]])
89+
} else {
90+
# remove
91+
if (length(which.axis) > 1){
92+
# remove all axis functions other than the first one
93+
object[[as.side_name(side)]] <- object[[as.side_name(side)]][-which.axis[!which.axis %in% head(which.axis, 1)]]
94+
}
95+
object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user_args[[fun.name]])
96+
}
8097
object[[as.side_name(side)]][['usr.axes']] <- TRUE
81-
object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user_args[[fun.name]])
98+
8299
if (!is.null(reverse)){
83100
object[[as.side_name(side)]][['reverse']] <- reverse
84101
}
@@ -89,9 +106,19 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL) {
89106
}
90107

91108
draw_axis <- function(object, side.name){
109+
# method isn't made for multiple axis calls
110+
which.axis <- which(names(object[[side.name]]) == 'axis')
111+
if (length(which.axis) > 1){
112+
for (axis.i in which.axis){
113+
tmp <- object
114+
tmp[[side.name]] <- tmp[[side.name]][-which.axis[which.axis %in% axis.i]]
115+
draw_axis(tmp, side.name)
116+
}
117+
118+
}
92119
axis.args <- object[[side.name]][['axis']]
93120
side.lim <- object[[side.name]][['lim']]
94-
121+
95122
axis.args$at <- get_axTicks(object, as.side(side.name))
96123

97124
# need a cleaner way to extract the non-axis args (such as n.minor and tcl.minor)
@@ -112,9 +139,7 @@ draw_axis <- function(object, side.name){
112139
axis.args$n.minor <- NULL
113140
axis.args$tcl.minor <- NULL
114141

115-
do.call('Axis', axis.args)
116-
117-
142+
do.call('Axis', axis.args)
118143

119144
# Minor axis:
120145

@@ -150,4 +175,4 @@ draw_axis <- function(object, side.name){
150175
axis.args$tcl <- tcl
151176
do.call('Axis', axis.args)
152177
}
153-
}
178+
}

R/function_args.R

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ function_args <- function(package, name, object, ..., use.default=paste0(name,'.
1414
params <- list(...)
1515

1616
if (!missing(object)) {
17-
params <- append_params(object, params)
17+
if (!is.null(names(object)))
18+
params <- append(object, params)
19+
else {
20+
params <- append(list(object), params)
21+
}
1822
} else {
19-
object=c()
23+
object = c() # replace w/ empty
2024
}
2125

2226
if (length(params) == 0)
2327
return(list())
2428

25-
2629
# // is there a method for this class?
2730
defFun <- getS3method(name,class(object),optional=TRUE) # will be NULL when object is missing
2831
if (is.null(defFun)){
@@ -55,20 +58,4 @@ function_args <- function(package, name, object, ..., use.default=paste0(name,'.
5558
return(params)
5659
}
5760

58-
append_params <- function(object, params){
59-
UseMethod('append_params')
60-
}
61-
62-
append_params.NULL <- function(object, params){
63-
params
64-
}
65-
66-
append_params.list <- function(object, params){
67-
append(object, params)
68-
}
69-
70-
append_params.default <- function(object, params){
71-
append(list(object), params)
72-
}
73-
7461
user_function_args <- function_args

tests/testthat/tests-axis.R

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ test_that("axis gsplot",{
1717
expect_true(all(names(gs) %in% c("side.1", "side.2", "side.3", "view.1.2", "global")))
1818

1919
gs <- gsplot() %>%
20-
lines(1:5, c(1,10,100,1000,10000), log="y", axes=FALSE) %>%
21-
axis(side=c(2,4), labels=FALSE, n.minor=4)
20+
lines(1:5, c(1,10,100,1000,10000), log="y", axes=FALSE) %>%
21+
axis(side=c(2,4), labels=FALSE, n.minor=4)
2222

2323
expect_false(gs$side.1$axes)
2424
expect_false(gs$side.2$axes)
@@ -46,6 +46,41 @@ test_that("axis reverse",{
4646

4747
})
4848

49+
context('multiple axis on the same side can be used')
50+
test_that("axis can append a second one",{
51+
gs <- gsplot() %>%
52+
points(0:1,0:1) %>%
53+
axis(side=1, at=c(0.5,1)) %>%
54+
axis(side=1, at=c(0.25, 0.75), append=TRUE)
55+
expect_equal(sum(names(gs$side.1) == 'axis'), 2)
56+
})
57+
58+
test_that("axis can append a third one and the forth clears them",{
59+
gs <- gsplot() %>%
60+
points(0:1,0:1) %>%
61+
axis(side=1, at=c(0.5,1)) %>%
62+
axis(side=1, at=c(0.25, 0.75), append=TRUE) %>%
63+
axis(side=1, at=c(0.45, 0.55), append=TRUE)
64+
65+
expect_equal(sum(names(gs$side.1) == 'axis'), 3)
66+
gs <- gsplot() %>%
67+
points(0:1,0:1) %>%
68+
axis(side=1, at=c(0.5,1)) %>%
69+
axis(side=1, at=c(0.25, 0.75), append=TRUE) %>%
70+
axis(side=1, at=c(0.45, 0.55), append=TRUE) %>%
71+
axis(side=1, at=c(0.33))
72+
expect_equal(sum(names(gs$side.1) == 'axis'), 1)
73+
expect_equal(gs$side.1$axis$at, 0.33)
74+
})
75+
76+
test_that("axis tracks append FALSE by default",{
77+
gs <- gsplot() %>%
78+
points(0:1,0:1) %>%
79+
axis(side=1, at=c(0.5,1)) %>%
80+
axis(side=1, at=c(0.25, 0.75)) %>%
81+
axis(side=1, at=c(0.45, 0.55), append=TRUE)
82+
expect_equal(sum(names(gs$side.1) == 'axis'), 2)
83+
})
4984

5085
context("axis user flipped on")
5186

tests/testthat/tests-points.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ test_that("graphics examples work", {
1010
lx <- seq(1, 5, length = 41)
1111
xy = xy.coords(x=10^lx,y=exp(-.5*lx^2))
1212
plot.xy(xy, type='p')
13-
14-
plot(1,3)
15-
points(data.frame(1,2), col='red')
16-
13+
1714
})
1815

1916
context("points arguments")

0 commit comments

Comments
 (0)