huxtable (version 0.3.1)

rowspecs: Row and column specifications

Description

Row and column specifications

Arguments

The basics

The set_* functions for cell properties all have arguments like this: set_property(ht, row, col, value, byrow = FALSE).

You can treat row and col arguments like arguments to [ for a data frame. But there are a few extra tricks:

  • Write set_property(ht, x), omitting row and col, to set the property to x for all cells.

  • Use everywhere to refer to all rows or all columns.

  • Use final(n) to refer to the last n rows or columns.

  • Use evens to get only even rows/columns and odds for only odd ones.

  • Use every(n, from = m) to get every nth row/column starting at row/column m. Use every(1) or just every() to get all rows or columns.

  • Use where(cond), and omit the col argument, to get cells where cond is TRUE.

  • Set byrow = TRUE to set properties by row rather than by column.

The gory details

Here is how the row and col arguments are parsed:

  • If there are two arguments (excluding byrow) then the second argument is taken as the value and is set for all rows and columns.

  • If there are three arguments, then the third argument is taken as the value, and row must be a matrix with two columns. Each row of this matrix gives the row, column indices of a single cell. This uses R's little known feature of subsetting with matrices - see Extract.

  • If there are four arguments:

    • If row or col is numeric, character or logical, it is evaluated just as in standard subsetting.

    • If row or col is a function,it is called with two arguments: the huxtable, and the dimension number being evaluated, i.e. 1 for rows, 2 for columns. It must return a vector of column indices. evens, odds, every and final return functions for this purpose.

Examples

Run this code
# NOT RUN {
ht <- huxtable(a = 1:5, b = 5:1)
ht <- set_font(ht, 2:4, 1:2, 'times')
font(ht)
ht <- set_font(ht, where(ht == 1), 'palatino')
font(ht)
ht <- set_font(ht, odds, evens, 'dingbats')
font(ht)
ht <- set_align(ht, 2:3, 1:2, c('right', 'center'), byrow = TRUE)
align(ht)
# }

Run the code above in your browser using DataCamp Workspace