Dokuwiki table syntax uses a | to delimit cells (and optionally, ^ to delimit the header row). The dokuwiki() function in the Tmisc package (new in version 0.1.15) takes a data frame and prints a Dokuwiki-formatted table to the console (and, by default, copies the table to the system clipboard if you’re using a Mac.).
Let’s use the first few rows of the built-in iris data as an example.
mydata <- head(iris)
mydata
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
Now, use the dokuwiki() function:
# install.packages("Tmisc")
library(Tmisc)
dokuwiki(mydata)
Displayed to the screen and written to the Mac OS X clipboard:
Copied to clipboard:
^Sepal.Length^Sepal.Width^Petal.Length^Petal.Width^Species^
|5.1|3.5|1.4|0.2|setosa|
|4.9|3|1.4|0.2|setosa|
|4.7|3.2|1.3|0.2|setosa|
|4.6|3.1|1.5|0.2|setosa|
|5|3.6|1.4|0.2|setosa|
|5.4|3.9|1.7|0.4|setosa|
By default, data is copied to the clipboard and row.names are never displayed. These can be changed, and so can the column delimiters if you’d like. Also, dokuwiki() works in a pipeline, so if you’re using dplyr, you can do something like this:
library(dplyr)
mtcars %>%
head(10) %>%
select(mpg:wt) %>%
dokuwiki(clip=FALSE, row.names=TRUE)
^ ^mpg^cyl^disp^hp^drat^wt^
|Mazda RX4|21|6|160|110|3.9|2.62|
|Mazda RX4 Wag|21|6|160|110|3.9|2.875|
|Datsun 710|22.8|4|108|93|3.85|2.32|
|Hornet 4 Drive|21.4|6|258|110|3.08|3.215|
|Hornet Sportabout|18.7|8|360|175|3.15|3.44|
|Valiant|18.1|6|225|105|2.76|3.46|
|Duster 360|14.3|8|360|245|3.21|3.57|
|Merc 240D|24.4|4|146.7|62|3.69|3.19|
|Merc 230|22.8|4|140.8|95|3.92|3.15|
|Merc 280|19.2|6|167.6|123|3.92|3.44|
If copied into a dokuwiki page, it’s rendered nicely:
| mpg | cyl | disp | hp | drat | wt | |
|---|---|---|---|---|---|---|
| Mazda RX4 | 21.0 | 6 | 160.0 | 110 | 3.90 | 2.620 |
| Mazda RX4 Wag | 21.0 | 6 | 160.0 | 110 | 3.90 | 2.875 |
| Datsun 710 | 22.8 | 4 | 108.0 | 93 | 3.85 | 2.320 |
| Hornet 4 Drive | 21.4 | 6 | 258.0 | 110 | 3.08 | 3.215 |
| Hornet Sportabout | 18.7 | 8 | 360.0 | 175 | 3.15 | 3.440 |
| Valiant | 18.1 | 6 | 225.0 | 105 | 2.76 | 3.460 |
| Duster 360 | 14.3 | 8 | 360.0 | 245 | 3.21 | 3.570 |
| Merc 240D | 24.4 | 4 | 146.7 | 62 | 3.69 | 3.190 |
| Merc 230 | 22.8 | 4 | 140.8 | 95 | 3.92 | 3.150 |
| Merc 280 | 19.2 | 6 | 167.6 | 123 | 3.92 | 3.440 |
There are still a few remaining issues, but it’s mostly ready for general use.