| context {matrixset} | R Documentation |
Contexts dependent functions
Description
These functions are designed to work inside certain matrixset functions, to
have access to current group/matrix/row/column. Because of that, they will
not work in a general context.
The functions within which the context functions will work are apply_matrix(),
apply_row() and apply_column() - as well as their *_dfl/*dfw variant.
Note that "current" refers to the current matrix/group/row/column, as applicable, and possibly combined.
The context functions are:
-
current_n_row()andcurrent_n_column(). They each give the number of rows and columns, respectively, of the current matrix. -
current_row_name()andcurrent_column_name(). They provide the current row/column name. They are the context equivalent ofrownames()andcolnames(). -
current_row_info()andcurrent_column_info(). They give access to the current row/column annotation data frame. The are the context equivalent ofrow_info()andcolumn_info(). -
row_pos()andcolumn_pos(). They give the current row/column indices. The indices are the the ones before matrix subsetting. -
row_rel_pos()andcolumn_rel_pos(). They give the row/column indices relative to the current matrix. They are equivalent toseq_len(current_n_row())/seq_len(current_n_column()).
Usage
current_row_info()
current_column_info()
current_n_row()
current_n_column()
current_row_name()
row_pos()
row_rel_pos()
current_column_name()
column_pos()
column_rel_pos()
Value
See each individual functions for returned value when used in proper context. If used out of context, an error condition is issued.
Examples
# this will fail (as it should), because it is used out of context
is(try(current_n_row(), silent = TRUE), "try-error")
# this is one way to know the number of students per class in 'student_results'
student_results |>
apply_matrix_dfl(n = ~ current_n_row(), .matrix = 1)