Function and RStudio add-in allowing to quickly and automatically generate the code needed to render a table in a RMarkdown document using different formats (kable, kableExtra, DT and rhandsontable are currently implemented - if "None" is selected only the code to generate a new tibble with the provided content is provided).

insert_table(nrows = 3, ncols = 3, tbl_format = "kable",
  tbl_name = "my_tbl", colnames = NULL)

Arguments

nrows

`numeric` number of rows of the generated empty table, Default: 1 (ignored if calling the addin from an empty Rmd line)

ncols

`numeric` number of columns of the generated empty table, Default: 1 (ignored if calling the addin from an empty Rmd line)

tbl_format

`character` [`kable` | `kableExtra - html` | `kableExtra - pdf` | `DT` | `rhandsontable` | `None`] format required for the table to be created (ignored if calling as an addin)

tbl_name

`character` name required for the table to be created (ignored if calling as an addin)

colnames

`character` of length ncols containing the desired column names (ignored if calling as an addin)

Value

returns the code required to create a table in a Rmd file with the required format.
When calling as an add-in: * if the call is done when the cursor is on a empty selection the user can enter also the number of rows and columns and the code to generate a empty tribble with the specified dimensions is also created; * if the call is done when the cursor is on a non-empty selection the user can only select the output format, and the add-in returns the code needed to create a table named as the selected text, with the specified format

When called as a function: * the code to generate a empty tribble with the specified dimensions is created (defaults are used if any parameter is not passed), followed by the code needed to create a table with the specified format. The results are sent back to the console.

Examples

if (FALSE) { # From the console, use: insert_table(nrows = 4, ncols = 3, tbl_format = "DT") # From a "Rmd" file and within RStudio, place the cursor on a empty line or # select the name a data.frame within a "R" chunk, then click on "Addins" # and select "Insert Table" }