|
1 | 1 | ##' @method [[ aplot |
2 | 2 | ##' @export |
3 | 3 | `[[.aplot` <- function(x, i){ |
4 | | - x$plotlist[[i]] |
| 4 | + if(inherits(i, "numeric")){ |
| 5 | + return(x$plotlist[[i]]) |
| 6 | + } |
| 7 | + NextMethod() |
5 | 8 | } |
6 | 9 |
|
7 | 10 | ##' @method [ aplot |
8 | 11 | ##' @export |
9 | 12 | `[.aplot` <- function(x, i, j, ...){ |
10 | | - x[[x$layout[i, j]]] |
| 13 | + if (inherits(i, "numeric") && inherits(i, "numeric")){ |
| 14 | + return(x[[x$layout[i, j]]]) |
| 15 | + } |
| 16 | + NextMethod() |
11 | 17 | } |
12 | 18 |
|
13 | 19 | ##' @method [[<- aplot |
14 | 20 | ##' @export |
15 | 21 | `[[<-.aplot` <- function(x, i, value){ |
16 | | - if(!inherits(value, 'ggplot')){ |
17 | | - stop('The value should be a ggplot object.') |
| 22 | + if (inherits(i, "numeric")){ |
| 23 | + if(!inherits(value, 'ggplot')){ |
| 24 | + stop('The value should be a ggplot object.') |
| 25 | + } |
| 26 | + |
| 27 | + x$plotlist[[i]] <- value |
| 28 | + return(x) |
18 | 29 | } |
19 | | - x$plotlist[[i]] <- value |
| 30 | + x <- NextMethod(value) |
20 | 31 | return(x) |
21 | 32 | } |
22 | 33 |
|
23 | 34 |
|
24 | 35 | ##' @method [<- aplot |
25 | 36 | ##' @export |
26 | 37 | `[<-.aplot` <- function(x, i, j, value){ |
27 | | - if (!inherits(value, 'ggplot')){ |
28 | | - stop('The value should be a ggplot object.') |
29 | | - }else if (is.na(x$layout[i, j])){ |
30 | | - stop(paste0('The subplot which local in row ', i, |
31 | | - ' and col ', j, |
32 | | - ' is NULL, it can not be replaced.')) |
| 38 | + if (inherits(i, "numeric") && inherits(i, "numeric")){ |
| 39 | + if (!inherits(value, 'ggplot')){ |
| 40 | + stop('The value should be a ggplot object.') |
| 41 | + }else if (is.na(x$layout[i, j])){ |
| 42 | + stop(paste0('The subplot which local in row ', i, |
| 43 | + ' and col ', j, |
| 44 | + ' is NULL, it can not be replaced.')) |
| 45 | + } |
| 46 | + x[[x$layout[i, j]]] <- value |
| 47 | + return(x) |
33 | 48 | } |
34 | | - x[[x$layout[i, j]]] <- value |
| 49 | + x <- NextMethod(value) |
35 | 50 | return(x) |
36 | 51 | } |
37 | 52 |
|
|
0 commit comments