You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: R/gen-list.r
+31-15
Original file line number
Diff line number
Diff line change
@@ -17,18 +17,21 @@
17
17
#' \item For \code{gen.vector} a value (i.e., a vector of length 1) is expected.
18
18
#' \item For \code{gen.data.frame} a (named) vector or list is expected which describes one row of the data frame.
19
19
#' \item For \code{gen.matrix} either a (named) vector/list (like \code{gen.data.frame}) or a scalar is expected.
20
-
#' In the latter case we expect exactly two variables (inducing rows/columns) within the \code{...} arguments.
20
+
#' In the latter case we expect exactly two variables (inducing rows and columns where the order depends on \code{byrow}) within the \code{...} arguments.
21
21
#' }
22
22
#' Within \code{expr} it is allowed to use functions and predefined constants from the parent environment.
23
23
#' @param ... Arbitrary many variable ranges and conditions.
24
24
#' For all free variables occurring in \code{expr} a range must be assigned, e.g., \code{x = 1:3, y = 1:5} for an expression \code{x + y}.
25
25
#' At least one variable range is required.
26
26
#' The ranges may depend on each other, e.g., \code{x = 1:3, y = x:3} or a substitution like \code{x = 1:3, y = 2 * x} is allowed.
27
-
#' The generated values can be further restricted by conditions (like \code{x <= y}).
28
-
#'
27
+
#' The generated values can be further restricted by conditions like \code{x <= y}.
28
+
#' @param byrow Logical. If \code{FALSE} (the default), the elements of a vector within \code{expr} are taken as columns.
29
+
#' Otherwise, they are taken as rows.
30
+
#'
29
31
#' @return
30
32
#'
31
-
#' The result of \code{gen.list} is a list (a vector for \code{gen.vector}) containing an entry for each combination of the free variables (i.e., the Cartesian product), where all the free variables in \code{expr} are substituted.
33
+
#' The result of \code{gen.list} is a list (a vector for \code{gen.vector}) containing an entry for each combination of the free variables (i.e., the Cartesian product),
34
+
#' where all the free variables in \code{expr} are substituted.
32
35
#' The function \code{gen.vector} returns a vector while \code{gen.list} may contain also more complex substructures (like vectors or lists).
33
36
#'
34
37
#' The output of \code{gen.data.frame} is a data frame where each substituted \code{expr} entry is one row.
@@ -42,8 +45,10 @@
42
45
#' Each substituted \code{expr} entry is one row of the matrix.
43
46
#' In contrast to \code{gen.data.frame}, column names are not auto-generated, e.g., \code{gen.matrix(c(a_1, a_2), a_ = 1:2)} is an unnamed matrix.
44
47
#' If the \code{expr} argument has explicit names (e.g., \code{c(a_1 = a_1, a_2 = a_2)}), these column names are assigned to the resulting matrix.
45
-
#' \item It's a matrix where the rows/columns are induced by the first/second variable, if \code{expr} is a scalar, and no names or conditions are given.
48
+
#' \item It's a matrix where the rows and columns are induced by the two variables within \code{...}, if \code{expr} is a scalar, and no names or conditions are given.
49
+
#' If \code{byrow} is \code{FALSE}, the second variable (i.e., the inner loop) refers to the columns, otherwise it refers to the rows.
46
50
#' For instance, \code{gen.matrix(i + j, i = 1:3, j = 1:2)} is a matrix with 3 rows and 2 columns.
51
+
#' For \code{gen.matrix(i + j, i = 1:3, j = 1:2, byrow = TRUE)} we get 2 rows and 3 columns.
47
52
#' }
48
53
#'
49
54
#' All expressions and conditions are applied to each combination of the free variables separately, i.e., they are applied row-wise and not vector-wise.
@@ -87,8 +92,9 @@
87
92
#' For instance, \code{"var{x + 1}_{{a}}"} is transformed into \code{"var2_{a}"} for \code{x = 1}.
88
93
#'
89
94
#'
90
-
#' @seealso \code{\link{gen.list.expr}} to generate expressions to be evaluated later,
91
-
#' \code{\link{gen.named.list.expr}} to generate named structures,
95
+
#' @seealso
96
+
#' \code{\link{gen.named.list}} to generate named structures,
97
+
#' \code{\link{gen.list.expr}} to generate expressions to be evaluated later,
92
98
#' \code{\link{gen.logical.and}} to generate logical and/or conditions,
93
99
#' and \link{listcompr} for an overview of all list comprehension functions.
0 commit comments