|
1 | 1 | #' List comprehensions for R |
2 | 2 | #' |
3 | | -#' \itemize{\item{\code{to_list}}{ converts usual R loops expressions to list producers. |
4 | | -#' Expression should be started with \code{for} , \code{while} or |
5 | | -#' \code{repeat}. You can iterate over multiple lists if you provide several |
6 | | -#' loop variables in backticks. See examples.} |
7 | | -#' \item{\code{to_vec}}{ is the same as 'to_list' but return vector. See examples.} |
8 | | -#' \item{\code{alter}}{ return the same type as its argument but with modified |
| 3 | +#' - `to_list` converts usual R loops expressions to list producers. |
| 4 | +#' Expression should be started with `for`, `while` or |
| 5 | +#' `repeat`. You can iterate over multiple lists if you provide several |
| 6 | +#' loop variables in backticks. See examples. |
| 7 | +#' - `to_vec` is the same as 'to_list' but return vector. See examples. |
| 8 | +#' - `alter` returns the same type as its argument but with modified |
9 | 9 | #' elements. It is useful for altering existing data.frames or lists. See |
10 | | -#' examples.} |
11 | | -#' \item{\code{exclude}}{ is an auxiliary function for dropping elements in |
12 | | -#' 'alter'. There are no arguments for this function.} |
13 | | -#' } |
14 | | -#' @param expr expression which starts with \code{for} , \code{while} or \code{repeat}. |
15 | | -#' @param recursive logical. Should unlisting be applied to list components of result? See \link[base]{unlist} for details. |
16 | | -#' @param use.names logical. Should names be preserved? See \link[base]{unlist} for details. |
| 10 | +#' examples. |
| 11 | +#' - `exclude` is an auxiliary function for dropping elements in |
| 12 | +#' `alter`. There are no arguments for this function. |
| 13 | +#' |
| 14 | +#' @param expr expression which starts with `for`, `while` or `repeat`. |
| 15 | +#' @param recursive logical. Should unlisting be applied to list components of result? See [unlist][base::unlist] for details. |
| 16 | +#' @param use.names logical. Should names be preserved? See [unlist][base::unlist] for details. |
17 | 17 | #' @param data data.frame/list/vector which we want to alter |
18 | | -#' @return list for \code{to_list} and vector for \code{to_vec} |
| 18 | +#' @return list for `to_list` and vector for `to_vec` |
19 | 19 | #' @export |
20 | 20 | #' |
21 | 21 | #' @examples |
@@ -141,20 +141,20 @@ add_expansion_to_loop = function(expr){ |
141 | 141 | } |
142 | 142 |
|
143 | 143 | is_loop = function(expr){ |
144 | | - if(!is.call(expr)) return(FALSE) |
| 144 | + is.call(expr) || return(FALSE) |
145 | 145 | first_item = expr[[1]] |
146 | 146 | identical(first_item, quote(`for`)) ||identical(first_item, quote(`while`)) ||identical(first_item, quote(`repeat`)) |
147 | 147 | } |
148 | 148 |
|
149 | 149 | is_for_loop = function(expr){ |
150 | | - if(!is.call(expr)) return(FALSE) |
| 150 | + is.call(expr) || return(FALSE) |
151 | 151 | first_item = expr[[1]] |
152 | 152 | identical(first_item, quote(`for`)) |
153 | 153 | } |
154 | 154 |
|
155 | 155 | has_loop_inside = function(expr){ |
156 | | - if(!is.call(expr)) return(FALSE) |
157 | | - if(is_loop(expr)) return(TRUE) |
| 156 | + is.call(expr) || return(FALSE) |
| 157 | + !is_loop(expr) || return(TRUE) |
158 | 158 | any( |
159 | 159 | unlist( |
160 | 160 | lapply(as.list(expr), has_loop_inside), |
|
0 commit comments