@@ -24,13 +24,17 @@ calc_views <- function(gsplot){
2424 return (views )
2525}
2626
27+ which_views <- function (gsplot ){
28+ grep(' view.' , names(gsplot ))
29+ }
30+
2731views <- function (gsplot ){
28- gsplot [grep( ' view. ' , names( gsplot ) )]
32+ gsplot [which_views( gsplot )]
2933}
3034
3135non_views <- function (gsplot ){
3236 non.views <- gsplot
33- non.views [grep( ' view. ' , names( non.views ) )] <- NULL
37+ non.views [which_views( non.views )] <- NULL
3438 return (non.views )
3539}
3640
@@ -92,7 +96,7 @@ which_reals <- function(values, na.value){
9296
9397}
9498set_view_window <- function (views , param , na.value = NA , remove = TRUE , ignore = NULL ){
95- view_i <- grep( ' view. ' , names( views ) )
99+ view_i <- which_views( views )
96100 for (i in view_i ){
97101 values <- lapply(views [[i ]][! names(views [[i ]]) %in% ignore ], function (x ) strip_pts(x , param ))
98102 val.i <- which_reals(values , na.value )
@@ -198,15 +202,15 @@ views_with_side <- function(views, side){
198202 if (length(side ) > 1 )
199203 stop(' side can only be length of 1' )
200204 with.side = lapply(views , function (x ) any(x [[' window' ]][[' side' ]] %in% side ))
201- view.match = unname(unlist(with.side [grep( ' view. ' , names( views ) )]))
205+ view.match = unname(unlist(with.side [which_views( views )]))
202206 if (is.null(view.match ) || ! any(view.match ))
203207 return (NULL )
204208 else
205209 return (which(view.match ))
206210}
207211
208212get_view_side <- function (views , view_i , param ){
209- i = grep( ' view. ' , names( views ) )[view_i ]
213+ i = which_views( views )[view_i ]
210214 sides <- views [[i ]][[' window' ]][[' side' ]]
211215 if (param == ' y' )
212216 return (sides [which(sides %% 2 == 0 )])
@@ -218,7 +222,7 @@ get_view_side <- function(views, view_i, param){
218222
219223summarize_args <- function (views , param , na.value , ignore = ' gs.config' ){
220224
221- view_i <- grep( ' view. ' , names( views ) )
225+ view_i <- which_views( views )
222226 values <- list ()
223227 for (i in view_i ){
224228 x <- views [[i ]][! names(views [[i ]]) %in% ignore ]
@@ -260,7 +264,7 @@ set_window <- function(list){
260264 listOut <- list
261265 pars <- list [[' par' ]]
262266
263- for (j in grep( ' view. ' , names( list ) )){
267+ for (j in which_views( list )){
264268
265269 window <- list [[j ]][[' window' ]]
266270 plots <- list [[j ]]
0 commit comments