Skip to contents

This function wraps numerous DT features into a single, well-parametrized interface.

Usage

robotable(
  d,
  title = NULL,
  subtitle = "",
  caption = NULL,
  rounding = getOption("roboplot.rounding"),
  width = getOption("roboplot.width"),
  height = NULL,
  flag = "",
  unit = "",
  dateformat = NULL,
  pagelength = 10,
  info_text = NULL,
  heatmap = NULL,
  na_value = "",
  class = NULL,
  searchable = T,
  sortable = T,
  col_widths = NULL,
  artefacts = getOption("roboplot.artefacts")$auto,
  ...
)

Arguments

d

Data frame. Data to be created a table from.

title, subtitle

Characters. Labels for plot elements.

caption

Function or character. Use set_caption().

rounding

Double, named if vector. Controls the rounding of numeric columns. Give a named vector for specific columns. Default is set with set_roboplot_options()

height, width

Numeric. Height and width of the table. Default width is NULL for responsive tables, give a value for static table dimensions.

flag, unit

Character vectors. Use "+" for flag if you want to flag a numeric column for positive values. Unit is prepended to values in a numeric column. Name the units with column names from d if you want to target specific columns.

dateformat

Character. Controls how to format dates displayed on the table. robotable() attempts to determine the proper format if left NULL.

pagelength

Numeric. Controls how many rows are displayed on the table. If d contains more rows than this, robotable() adds navigation elements.

info_text

Character. Optional. If included, this text will be displayed with a popup when the info button in the table modebar is clicked.

heatmap

Function. Use set_heatmap(). Color-codes numeric columns.

na_value

Character. How NA values are displayed.

class

Character vector. Controls the basic datatable appearance. You may combine any of "cell-border", "compact","hover","nowrap","row-border" and / or "stripe". The default use is "stripe", "hover" and "row-border".

searchable, sortable

Logical. Control whether the robotable() columns have searching or sorting when navigation is displayed.

col_widths

Named numeric vector. Must sum to 100 or lower. Sets the percentage widths taken by column by name. Columns not named will have the excess space divided evenly between them. For narrow screens the widths cannot be adhered to.

artefacts

Function. Use set_artefacts(). Controls file exports. Currently unable to make static exports, only html files.

...

Placeholder for other parameters.

Value

A list of classes datatable, htmlwidget, and roboplotr.robotable

Examples

# You can use `robotable()` to create html tables
#
energiantuonti |> robotable()
# # No matter if you have any number date, character or numeric columns, robotable() # handles the formatting automatically. # d <- energiantuonti |> dplyr::filter(Alue %in% c("Ruotsi","USA")) |> tidyr::unite(Tiedot, Alue, Suunta, sep = ", ") |> dplyr::arrange(Tiedot, time) |> tidyr::pivot_wider(names_from = Tiedot) |> dplyr::mutate(dplyr::across(where(is.numeric), ~ tidyr::replace_na(.x, 0))) |> dplyr::arrange(time) d |> robotable()
# # You can use `pagelength` to control how many rows are shown at once, # `info_text` to add any information you wish describe about the table, and # `heatmap` parameter if you want to color-code any numeric values across the # table. See [set_heatmap()]. # d |> robotable(heatmap = set_heatmap(), pagelength = 50, info_text = "Testing the info button.")
# You can use `class` to control visuals, providing a character vector of html # classes used by the table. Available options are "cell-border", "compact", # "hover", "nowrap", "row-border" and "stripe", with the default being "stripe", # "hover" and "row-border". Column widths can be specified by giving a named # vector where the values are percentages of total width. Navigating options # can be disabled by 'searchable' and 'sortable'. d |> robotable( class = c("compact", "nowrap"), searchable = FALSE, sortable = FALSE, col_widths = c("USA, Vienti" = 50) )