Long-awaited updates to htmlTable

Lets celebrate 2019 with some updates to my most popular package ever, the htmlTable. The image is CC by
Thomas Hawk

One of the most pleasant surprises has been the popularity of my htmlTable-package with more than 100k downloads per month. This is all thanks to more popular packages relying on it and the web expanding beyond its original boundaries. As a thank you I have taken the time to update and fix some features (the 1.13 release) – enjoy!

Grouping column headers

Grouping columns is a powerful feature that allows you to quickly generate more interesting tables. Unfortunately the cgroup has previously required matrix input for this feature that even I as the author sometimes struggled with. Now you can provide a list in a much more user friendly manner:

Super
First   Second
No %   No %
Group A 20 5   380 95
Group B 11 55   9 45

The n.cgroup can be either a combination of the cgroup below but the exact same table can be created through providing list(c(4),c(2,2)) as the n.cgroup.

Auto-counting tspanners

Even more common than grouping columns is probably grouping data by rows. The htmlTable allows you to do this by rgroup and tspanner. The most common approach is by using rgroup as the first row-grouping element but with larger tables you frequently want to separate concepts into separate sections. Here’s a more complex example. This has previously been a little cumbersome to to counting the rows of each tspanner but now you’re able to (1) leave out the last row, (2) specify the number of rgroups instead of the number of rows. The latter is convenient as the n.tspanner must align with the underlying rgroup. Here’s an example:

Extremely fake data
  Cases   Controls
Total   No (%)   No (%)
First experiment
Aspirin
  Group A 400   20 (5.0)   380 (95.0)
  Group B 1,340   110 (8.2)   1,230 (91.8)
Intermittent compression
  Group C 58   2 (3.4)   56 (96.6)
  Group D 50   17 (34.0)   33 (66.0)
Second experiment
Aspirin
  Group A 400   40 (10.0)   360 (90.0)
  Group B 1,330   230 (17.3)   1,100 (82.7)
Intermittent compression
  Group C 58   8 (13.8)   50 (86.2)
  Group D 50   10 (20.0)   40 (80.0)

The txtRound now has digits.nonzero argument

The txtRound is similar to R’s round but returns a string that makes sure that all your values are presented with the same number of digits.

Under some circumstances you are close to 0 and you want to retain more digits, hence the new
digits.nonzero argument:

New function vector2string

As a package author I think the majority of my code is dedicated towards providing good error message. A common issue is that you have two vectors that don’t match. For this purpose I’ve created the vector2string. This makes it easier to write your stop messages. You simply provide any vector and get a string back:

Here’s how I use is in one of my functions:

Summary

These are tiny additions and everything should work just as it has in previous versions. Hopefully it will save you some time and make your life easier! Enjoy!

Flattr this!

This entry was posted in R. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.