[autofilling, tablefill, latex, lyx, markdown]


Why should you use tableFill?

tableFill allows to automatically update Latex, LyX and Markdown tables. Its primary aim is to create reproducible reports, which can be automatically updated.

How to install tableFill?

Run the following code in the command line (Windows) or terminal (Mac).

pip install git+https://github.com/mcaceresb/tablefill
tablefill --help

How to use tableFill?

There are three steps to use tableFill function. To use tableFill, you should create one template file and a text file of results.

The template file is a markdown file that will be filled with results later on. The text file of results includes the results that you want to fill the table in the template. These results can be anything such as regression results and summary statistics.

Step 1 : Create a markdown document template

This template will be filled with the results. The results can be anything ranging from regression results to summary statistics.

Below, there is an example of a template table. This tableFill function will look for a tag “example” in the when it fills the table.

<!-- tablefill:start tab:example -->

| Outcomes     | N    | Mean | (Std.) |
| ------------ | ---- | ---- | ------ |
| Outcomes ### | #0,# | #1,# | (#2,#) |
| Outcomes ### | #0,# | #1,# | (#2,#) |
| Outcomes ### | #0,# | #1,# | (#2,#) |
| Outcomes ### | #0,# | #1,# | (#2,#) |

<!-- tablefill:end -->

Step 2 : Get your results and convert them to a text file

You should save you results (e.g., from a regression, summary statistics) in a text file.

Warning

The tag name of the results should correspond to the the tag name of the section in the template that you want to fill in

Below, there is a function for saving your results in a text file in R.

saveTable <- function (outfile, tag, outmatrix) {
    cat(tag,
        sep    = "\n",
        file   = outfile,
        append = TRUE)

  # "outfile" : the name of the text file that will have your results
  # "tag" : the name of the table that the tablefill function will look for when
  #filling the placeholders.
  # "outmatrix" : the matrix of the results

    write.table(outmatrix,
                file      = outfile,
                sep       = "\t",
                append    = TRUE,
                quote     = FALSE,
                col.names = FALSE,
                row.names = FALSE)
}

The below code creates a text file named “test.txt”. It saves the matrix “matrix(runif(16), 4, 4)” under the tag name “example”. The tableFill function will then look for a tag “example” in the template file to fill the blanks with this matrix.

saveTable("test.txt", "<tab:example>", matrix(runif(16), 4, 4))
}

Step 3 : Run the tableFill function in the Command Line (Windows) / Shell (Mac)

In the last step, you run the tableFill function in the Command Line or Shell as seen below. What the below code does is that it fills the “template.md” file with “test.txt” and saves the output file under the name “filled.tex”.

tablefill -i test.txt -o filled.tex template.md
}

Example repository

If you want to check out more about tableFill and see a basic example on how to use it, you can check out the GitHub repository below :


The structure of the repository is as follows :

tableFill Repository
│
├── template.md ........ includes a markdown document template
├── saveTable.R ........ includes a function to save the results in a text file in R
├── test.txt  ........ saves the results from the saveTable.R file in the txt format
Warning

Make sure that you do not overwrite the txt file that you save your results (e.g., “test.txt” in the tableFill repository)

Additional Resources

  1. https://mcaceresb.github.io/tablefill/index.html
  2. https://github.com/mcaceresb/tablefill