Knitting tables with kable

The kable function from the knitr package allows to display nicely formatted tables using R Markdown, as explained here. I recently encountered unexpected behaviour of kable when calling it from lapply or a function, which led to this post on StackOverflow. The answers were very detailed and enlightening, and I invite you to read them. They could be summarized in two points: be aware of side-effects, and prefer cat (with new lines) to print.

Batch tsv to csv conversion

I recently had to convert tables from tsv to csv format and found several ways to do it in this thread from StackOverflow, including the tsv2csv.py Python script below:

import sys
import csv

tabin = csv.reader(sys.stdin, dialect=csv.excel_tab)
commaout = csv.writer(sys.stdout, dialect=csv.excel)
for row in tabin:
    commaout.writerow(row)

Here is a simple wrapper Bash script to run the conversion in batch:

for file in *.tsv
do
    python tsv2csv.py < $file > ${file%.*}.csv
done