Skip to content

Commit 68f294b

Browse files
author
Lindsay Carr
authored
Merge pull request #420 from lindsaycarr/indexLost
indexing allowed for points and lines
2 parents 98e3e0a + d7e1ab0 commit 68f294b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

R/function_args.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ function_args <- function(package, name, object, ..., use.default=paste0(name,'.
4545
names(params)[which(names(params) == "")] <- arg.names[seq_len(sum(names(params) == ""))]
4646
}
4747

48+
if(name %in% c('points', 'lines')){
49+
if(!is.null(params[['x']]) & is.null(params[['y']])){
50+
xy_args <- list(x = seq_along(params[['x']]),
51+
y = params[['x']])
52+
params <- append_replace(params, xy_args)
53+
}
54+
}
4855

4956
# // re-order
5057
sort.i <- seq_len(length(params))

tests/testthat/test-arguments.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
context("lining up default arguments")
22
test_that("setting params with other default works as expected",{
3-
expect_equal(gsplot:::function_args("grDevices","points", 1:5, y = NULL, 'label', use.default='xy.coords'),
4-
list(x=1:5, y=NULL,xlab='label'))
3+
expect_equal(gsplot:::function_args("grDevices","points", 5:10, y = NULL, 'label', use.default='xy.coords'),
4+
list(x=1:6, y=5:10,xlab='label'))
55
})
66

77
test_that("setting params with class match works as expected",{

tests/testthat/tests-points.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_that("graphics examples work", {
1515

1616
context("points arguments")
1717
test_that("setting params works as expected",{
18-
expect_equal(gsplot:::function_args("graphics","points", 5, y = NULL), list(x=5, y=NULL))
18+
expect_equal(gsplot:::function_args("graphics","points", 5, y = NULL), list(x=1, y=5))
1919
expect_equal(gsplot:::function_args("graphics","points", y=5, x=0), list(x=0, y=5))
2020
})
2121

@@ -58,3 +58,18 @@ test_that("points.gsplot accepts formulas",{
5858

5959
})
6060

61+
test_that("points works with indexing", {
62+
63+
x <- 7:10
64+
gs <- gsplot() %>%
65+
points(x)
66+
expect_equal(class(gs$view.1.2$points$y), "integer")
67+
expect_equal(gs$view.1.2$points$x, seq_along(x))
68+
69+
70+
oct_dates <- seq(as.Date("2015-10-11"), as.Date("2015-10-15"), by="days")
71+
gs_dates <- gsplot() %>%
72+
points(oct_dates)
73+
expect_equal(class(gs_dates$view.1.2$points$y), "Date")
74+
expect_equal(gs_dates$view.1.2$points$x, seq_along(oct_dates))
75+
})

0 commit comments

Comments
 (0)