insert_column: Insert a row or column

Description Usage Arguments Details Value See Also Examples

Description

These convenience functions wrap cbind or rbind for huxtables, to insert a single row or column.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
insert_column(
  ht,
  ...,
  after = 0,
  fill = NULL,
  rowspan = 1,
  copy_cell_props = TRUE
)

insert_row(
  ht,
  ...,
  after = 0,
  fill = NULL,
  colspan = 1,
  copy_cell_props = TRUE
)

Arguments

ht

A huxtable.

...

Cell contents.

after

Insert the row/column after this position. 0 (the default) inserts as the first row/column.

fill

String. If ... contains fewer elements than there are columns/rows to fill, the remaining cells will be filled with this.

rowspan, colspan

Scalar integer. Sets the rowspan or colspan of the first cell only. The default NULL throws an error if there are too few elements.

copy_cell_props

Copy cell properties from the previous row or column (if after > 0). See cbind.huxtable().

Details

In insert_column only, you can use a column name for after.

Even if colspan or rowspan are greater than 1, you must still provide values for the hidden cells. Use fill = "" for this.

Value

The modified huxtable

See Also

add_rows() and add_columns(), which insert multiple rows/columns at once.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
insert_row(jams,
        c("Gooseberry", 2.15),
        after = 1
      )

insert_column(jams,
        c("Sugar", "50%", "60%", "40%"),
        after = "Price"
      )

insert_column(jams,
        "Sugar",
        after = "Price",
        fill = "50%"
      )

# don't forget to use `fill`:
insert_row(jams,
        "Jams and prices",
        fill = "",
        colspan = 2
      )

Example output

                              Type           Price  
                              Gooseberry      2.15  
                              Strawberry      1.90  
                              Raspberry       2.10  
                              Plum            1.80  

Column names: Type, Price
                          Type         Price    Sugar  
                          Strawberry    1.90   50.00%  
                          Raspberry     2.10   60.00%  
                          Plum          1.80   40.00%  

Column names: Type, Price,
                          Type         Price    Sugar  
                          Strawberry    1.90   50.00%  
                          Raspberry     2.10   50.00%  
                          Plum          1.80   50.00%  

Column names: Type, Price,
                              Jams and prices       
                              Type           Price  
                              Strawberry      1.90  
                              Raspberry       2.10  
                              Plum            1.80  

Column names: Type, Price

huxtable documentation built on May 15, 2021, 1:09 a.m.