htmlTable/ 0000755 0001762 0000144 00000000000 13572030437 012172 5 ustar ligges users htmlTable/NAMESPACE 0000644 0001762 0000144 00000002557 13572023061 013415 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(htmlTable,data.frame)
S3method(htmlTable,default)
S3method(htmlTable,matrix)
S3method(interactiveTable,default)
S3method(knit_print,htmlTable)
S3method(knit_print,interactiveTable)
S3method(print,htmlTable)
S3method(print,interactiveTable)
S3method(tidyHtmlTable,data.frame)
S3method(tidyHtmlTable,default)
S3method(txtRound,data.frame)
S3method(txtRound,default)
S3method(txtRound,matrix)
S3method(txtRound,table)
export(concatHtmlTables)
export(htmlTable)
export(htmlTableWidget)
export(htmlTableWidgetOutput)
export(interactiveTable)
export(outputInt)
export(pvalueFormatter)
export(renderHtmlTableWidget)
export(splitLines4Table)
export(tblNoLast)
export(tblNoNext)
export(tidyHtmlTable)
export(txtInt)
export(txtMergeLines)
export(txtPval)
export(txtRound)
export(vector2string)
import(checkmate)
import(htmlwidgets)
import(magrittr)
importFrom(grDevices,col2rgb)
importFrom(grDevices,colorRampPalette)
importFrom(htmltools,htmlEscape)
importFrom(knitr,asis_output)
importFrom(knitr,knit_print)
importFrom(methods,setClass)
importFrom(rstudioapi,getActiveDocumentContext)
importFrom(rstudioapi,isAvailable)
importFrom(stats,na.omit)
importFrom(stringr,str_replace)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_trim)
importFrom(utils,as.roman)
importFrom(utils,browseURL)
importFrom(utils,head)
importFrom(utils,tail)
htmlTable/README.md 0000644 0001762 0000144 00000145034 13412375537 013466 0 ustar ligges users [](https://travis-ci.org/gforge/htmlTable)
[](https://cran.r-project.org/package=htmlTable)
Basics
======
The **htmlTable** package is intended for generating tables using [HTML](http://en.wikipedia.org/wiki/HTML) formatting. This format is compatible with [Markdown](http://rmarkdown.rstudio.com/) when used for HTML-output. The most basic table can easily be created by just passing a `matrix` or a `data.frame` to the `htmlTable`-function:
```r
library(htmlTable)
# A simple output
output <- matrix(1:4,
ncol=2,
dimnames = list(list("Row 1", "Row 2"),
list("Column 1", "Column 2")))
htmlTable(output)
```
|
Column 1 |
Column 2 |
Row 1 |
1 |
3 |
Row 2 |
2 |
4 |
As of version 1.0.2 you **no longer need** to specify `results='asis'` for each `knitr` chunk.
Advanced
========
While it may be sufficient for basic tables a more advanced layout is often needed in medical publications with elements such as:
* row groups
* column spanners
* table spanners
* caption
* table footer
* zebra coloring (also know as *banding*):
+ rows
+ columns
As many journals require that a MS Word-document is submitted it is furthermore also important that the table imports correctly to a word processor, i.e. that the table doesn't only look nice in a web browser but also in the final document. The `htmlTable`-function is written for all these purposes.
**Note:** Due to GitHub CSS-styles the rows get automatically zebra-striped (in a bad way), borders get overridden and I haven't been able to figure out how to change this. See the vignette for a correct example: `vignette("general", package = "htmlTable")`
For demonstration purposes we will setup a basic matrix:
```r
mx <-
matrix(ncol=6, nrow=8)
rownames(mx) <- paste(c("1st", "2nd",
"3rd",
paste0(4:8, "th")),
"row")
colnames(mx) <- paste(c("1st", "2nd",
"3rd",
paste0(4:6, "th")),
"hdr")
for (nr in 1:nrow(mx)){
for (nc in 1:ncol(mx)){
mx[nr, nc] <-
paste0(nr, ":", nc)
}
}
```
Row groups
----------
The purpose of the row groups is to group variables that belong to the same group, e.g. a factored variable with more than two levels often benefit from grouping variables together.
```r
htmlTable(mx,
rgroup = paste("Group", LETTERS[1:3]),
n.rgroup = c(2,4,nrow(mx) - 6))
```
|
1st hdr |
2nd hdr |
3rd hdr |
4th hdr |
5th hdr |
6th hdr |
Group A |
1st row |
1:1 |
1:2 |
1:3 |
1:4 |
1:5 |
1:6 |
2nd row |
2:1 |
2:2 |
2:3 |
2:4 |
2:5 |
2:6 |
Group B |
3rd row |
3:1 |
3:2 |
3:3 |
3:4 |
3:5 |
3:6 |
4th row |
4:1 |
4:2 |
4:3 |
4:4 |
4:5 |
4:6 |
5th row |
5:1 |
5:2 |
5:3 |
5:4 |
5:5 |
5:6 |
6th row |
6:1 |
6:2 |
6:3 |
6:4 |
6:5 |
6:6 |
Group C |
7th row |
7:1 |
7:2 |
7:3 |
7:4 |
7:5 |
7:6 |
8th row |
8:1 |
8:2 |
8:3 |
8:4 |
8:5 |
8:6 |
We can easily mix row groups with regular variables by having an empty row group name `""`:
```r
htmlTable(mx,
rgroup = c(paste("Group", LETTERS[1:2]), ""),
n.rgroup = c(2,4,nrow(mx) - 6))
```
|
1st hdr |
2nd hdr |
3rd hdr |
4th hdr |
5th hdr |
6th hdr |
Group A |
1st row |
1:1 |
1:2 |
1:3 |
1:4 |
1:5 |
1:6 |
2nd row |
2:1 |
2:2 |
2:3 |
2:4 |
2:5 |
2:6 |
Group B |
3rd row |
3:1 |
3:2 |
3:3 |
3:4 |
3:5 |
3:6 |
4th row |
4:1 |
4:2 |
4:3 |
4:4 |
4:5 |
4:6 |
5th row |
5:1 |
5:2 |
5:3 |
5:4 |
5:5 |
5:6 |
6th row |
6:1 |
6:2 |
6:3 |
6:4 |
6:5 |
6:6 |
7th row |
7:1 |
7:2 |
7:3 |
7:4 |
7:5 |
7:6 |
8th row |
8:1 |
8:2 |
8:3 |
8:4 |
8:5 |
8:6 |
When mixing row groups with variables without row groups we may want to omit the bold formatting of the row group label:
```r
htmlTable(mx,
css.rgroup = "",
rgroup = c(paste("Group", LETTERS[1:2]), ""),
n.rgroup = c(2,4,nrow(mx) - 6))
```
|
1st hdr |
2nd hdr |
3rd hdr |
4th hdr |
5th hdr |
6th hdr |
Group A |
1st row |
1:1 |
1:2 |
1:3 |
1:4 |
1:5 |
1:6 |
2nd row |
2:1 |
2:2 |
2:3 |
2:4 |
2:5 |
2:6 |
Group B |
3rd row |
3:1 |
3:2 |
3:3 |
3:4 |
3:5 |
3:6 |
4th row |
4:1 |
4:2 |
4:3 |
4:4 |
4:5 |
4:6 |
5th row |
5:1 |
5:2 |
5:3 |
5:4 |
5:5 |
5:6 |
6th row |
6:1 |
6:2 |
6:3 |
6:4 |
6:5 |
6:6 |
7th row |
7:1 |
7:2 |
7:3 |
7:4 |
7:5 |
7:6 |
8th row |
8:1 |
8:2 |
8:3 |
8:4 |
8:5 |
8:6 |
Column spanners
---------------
A column spanner spans 2 or more columns:
```r
htmlTable(mx,
cgroup = c("Cgroup 1", "Cgroup 2"),
n.cgroup = c(2,4))
```
|
Cgroup 1 | |
Cgroup 2 |
|
1st hdr |
2nd hdr |
|
3rd hdr |
4th hdr |
5th hdr |
6th hdr |
1st row |
1:1 |
1:2 |
|
1:3 |
1:4 |
1:5 |
1:6 |
2nd row |
2:1 |
2:2 |
|
2:3 |
2:4 |
2:5 |
2:6 |
3rd row |
3:1 |
3:2 |
|
3:3 |
3:4 |
3:5 |
3:6 |
4th row |
4:1 |
4:2 |
|
4:3 |
4:4 |
4:5 |
4:6 |
5th row |
5:1 |
5:2 |
|
5:3 |
5:4 |
5:5 |
5:6 |
6th row |
6:1 |
6:2 |
|
6:3 |
6:4 |
6:5 |
6:6 |
7th row |
7:1 |
7:2 |
|
7:3 |
7:4 |
7:5 |
7:6 |
8th row |
8:1 |
8:2 |
|
8:3 |
8:4 |
8:5 |
8:6 |
It can sometimes be convenient to have column spanners in multiple levels:
```r
htmlTable(mx,
cgroup = rbind(c("", "Column spanners", NA),
c("", "Cgroup 1", "Cgroup 2")),
n.cgroup = rbind(c(1,2,NA),
c(2,2,2)))
```
|
| |
Column spanners |
|
| |
Cgroup 1 | |
Cgroup 2 |
|
1st hdr |
2nd hdr |
|
3rd hdr |
4th hdr |
|
5th hdr |
6th hdr |
1st row |
1:1 |
1:2 |
|
1:3 |
1:4 |
|
1:5 |
1:6 |
2nd row |
2:1 |
2:2 |
|
2:3 |
2:4 |
|
2:5 |
2:6 |
3rd row |
3:1 |
3:2 |
|
3:3 |
3:4 |
|
3:5 |
3:6 |
4th row |
4:1 |
4:2 |
|
4:3 |
4:4 |
|
4:5 |
4:6 |
5th row |
5:1 |
5:2 |
|
5:3 |
5:4 |
|
5:5 |
5:6 |
6th row |
6:1 |
6:2 |
|
6:3 |
6:4 |
|
6:5 |
6:6 |
7th row |
7:1 |
7:2 |
|
7:3 |
7:4 |
|
7:5 |
7:6 |
8th row |
8:1 |
8:2 |
|
8:3 |
8:4 |
|
8:5 |
8:6 |
Above example allows the column spanner to be a sum of the underlying cgroups (see n.cgroup), this is not required by the function:
```r
htmlTable(mx,
cgroup = rbind(c("", "Column spanners", NA),
c("", "Cgroup 1", "Cgroup 2")),
n.cgroup = rbind(c(1,5,NA),
c(2,1,3)))
```
|
| |
Column spanners |
|
| |
Cgroup 1 | |
Cgroup 2 |
|
1st hdr |
|
2nd hdr |
|
3rd hdr |
|
4th hdr |
5th hdr |
6th hdr |
1st row |
1:1 |
|
1:2 |
|
1:3 |
|
1:4 |
1:5 |
1:6 |
2nd row |
2:1 |
|
2:2 |
|
2:3 |
|
2:4 |
2:5 |
2:6 |
3rd row |
3:1 |
|
3:2 |
|
3:3 |
|
3:4 |
3:5 |
3:6 |
4th row |
4:1 |
|
4:2 |
|
4:3 |
|
4:4 |
4:5 |
4:6 |
5th row |
5:1 |
|
5:2 |
|
5:3 |
|
5:4 |
5:5 |
5:6 |
6th row |
6:1 |
|
6:2 |
|
6:3 |
|
6:4 |
6:5 |
6:6 |
7th row |
7:1 |
|
7:2 |
|
7:3 |
|
7:4 |
7:5 |
7:6 |
8th row |
8:1 |
|
8:2 |
|
8:3 |
|
8:4 |
8:5 |
8:6 |
Table spanners
--------------
A table spanner is similar to rgroup but has the primary purpose of combining 2 or more tables with the same columns into one:
```r
htmlTable(mx,
tspanner = paste("Spanner", LETTERS[1:3]),
n.tspanner = c(2,4,nrow(mx) - 6))
```
|
1st hdr |
2nd hdr |
3rd hdr |
4th hdr |
5th hdr |
6th hdr |
Spanner A |
1st row |
1:1 |
1:2 |
1:3 |
1:4 |
1:5 |
1:6 |
2nd row |
2:1 |
2:2 |
2:3 |
2:4 |
2:5 |
2:6 |
Spanner B |
3rd row |
3:1 |
3:2 |
3:3 |
3:4 |
3:5 |
3:6 |
4th row |
4:1 |
4:2 |
4:3 |
4:4 |
4:5 |
4:6 |
5th row |
5:1 |
5:2 |
5:3 |
5:4 |
5:5 |
5:6 |
6th row |
6:1 |
6:2 |
6:3 |
6:4 |
6:5 |
6:6 |
Spanner C |
7th row |
7:1 |
7:2 |
7:3 |
7:4 |
7:5 |
7:6 |
8th row |
8:1 |
8:2 |
8:3 |
8:4 |
8:5 |
8:6 |
Table caption
-------------
The table caption is simply the table description and can be either located above or below the table:
```r
htmlTable(mx[1:2,1:2],
caption="A table caption above")
```
Table 5: A table caption above |
|
1st hdr |
2nd hdr |
1st row |
1:1 |
1:2 |
2nd row |
2:1 |
2:2 |
```r
htmlTable(mx[1:2,1:2],
pos.caption = "bottom",
caption="A table caption below")
```
|
1st hdr |
2nd hdr |
1st row |
1:1 |
1:2 |
2nd row |
2:1 |
2:2 |
Table 6: A table caption below |
A more interesting detail that the function allows for is table numbering, initialized by:
```r
options(table_counter = TRUE)
```
```r
htmlTable(mx[1:2,1:2],
caption="A table caption with a numbering")
```
Table 1: A table caption with a numbering |
|
1st hdr |
2nd hdr |
1st row |
1:1 |
1:2 |
2nd row |
2:1 |
2:2 |
As we often want to reference the table number in the text there are two associated functions:
```r
tblNoLast()
```
```
## [1] 1
```
```r
tblNoNext()
```
```
## [1] 2
```
Table footer
------------
The footer usually contains specifics regarding variables and is always located at the foot of the table:
```r
htmlTable(mx[1:2,1:2],
tfoot="A table footer")
```
|
1st hdr |
2nd hdr |
1st row |
1:1 |
1:2 |
2nd row |
2:1 |
2:2 |
A table footer |
Putting it all together
-----------------------
Now if we want to do everything in one table it may look like this:
```r
htmlTable(mx,
align="r",
rgroup = paste("Group", LETTERS[1:3]),
n.rgroup = c(2,4,nrow(mx) - 6),
cgroup = rbind(c("", "Column spanners", NA),
c("", "Cgroup 1", "Cgroup 2†")),
n.cgroup = rbind(c(1,2,NA),
c(2,2,2)),
caption="A table with column spanners, row groups, and zebra striping",
tfoot="† A table footer commment",
cspan.rgroup = 2,
col.columns = c(rep("none", 2),
rep("#F5FBFF", 4)),
col.rgroup = c("none", "#F7F7F7"),
css.cell = "padding-left: .5em; padding-right: .2em;")
```
Table 2: A table with column spanners, row groups, and zebra striping |
|
| |
Column spanners |
|
| |
Cgroup 1 | |
Cgroup 2† |
|
1st hdr |
2nd hdr |
|
3rd hdr |
4th hdr |
|
5th hdr |
6th hdr |
Group A |
|
|
|
|
|
|
|
1st row |
1:1 |
1:2 |
|
1:3 |
1:4 |
|
1:5 |
1:6 |
2nd row |
2:1 |
2:2 |
|
2:3 |
2:4 |
|
2:5 |
2:6 |
Group B |
|
|
|
|
|
|
|
3rd row |
3:1 |
3:2 |
|
3:3 |
3:4 |
|
3:5 |
3:6 |
4th row |
4:1 |
4:2 |
|
4:3 |
4:4 |
|
4:5 |
4:6 |
5th row |
5:1 |
5:2 |
|
5:3 |
5:4 |
|
5:5 |
5:6 |
6th row |
6:1 |
6:2 |
|
6:3 |
6:4 |
|
6:5 |
6:6 |
Group C |
|
|
|
|
|
|
|
7th row |
7:1 |
7:2 |
|
7:3 |
7:4 |
|
7:5 |
7:6 |
8th row |
8:1 |
8:2 |
|
8:3 |
8:4 |
|
8:5 |
8:6 |
† A table footer comment |
htmlTable/data/ 0000755 0001762 0000144 00000000000 13407215301 013073 5 ustar ligges users htmlTable/data/SCB.rda 0000644 0001762 0000144 00000001245 13407215301 014174 0 ustar ligges users VMn@8?"VlPV,8Jv{X!NZl;, p \}Ì=kTU)#|/3f/A~PgY\UVnR%Va[
=Uw[Ux[\Oɬ5YeMVZHfU-g' (6¡*5X=^1S04k NhVrlrGyX,]ЬGa
bs^-w htmlTable/man/ 0000755 0001762 0000144 00000000000 13414117305 012740 5 ustar ligges users htmlTable/man/txtRound.Rd 0000644 0001762 0000144 00000003763 13572022513 015070 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/txtFrmt.R
\name{txtRound}
\alias{txtRound}
\alias{txtRound.default}
\alias{txtRound.data.frame}
\alias{txtRound.table}
\alias{txtRound.matrix}
\title{A convenient rounding function}
\usage{
txtRound(x, ...)
\method{txtRound}{default}(
x,
digits = 0,
digits.nonzero = NA,
txt.NA = "",
dec = ".",
scientific,
...
)
\method{txtRound}{data.frame}(x, ...)
\method{txtRound}{table}(x, ...)
\method{txtRound}{matrix}(x, digits = 0, excl.cols, excl.rows, ...)
}
\arguments{
\item{x}{The value/vector/data.frame/matrix to be rounded}
\item{...}{Passed to next method}
\item{digits}{The number of digits to round each element to.
If you provide a vector each element will apply to the corresponding columns.}
\item{digits.nonzero}{The number of digits to keep if the result is close to
zero. Sometimes we have an entire table with large numbers only to have a
few but interesting observation that are really interesting}
\item{txt.NA}{The string to exchange NA with}
\item{dec}{The decimal marker. If the text is in non-english decimal
and string formatted you need to change this to the apropriate decimal
indicator.}
\item{scientific}{If the value should be in scientific format.}
\item{excl.cols}{Columns to exclude from the rounding procedure.
This can be either a number or regular expression. Skipped if x is a vector.}
\item{excl.rows}{Rows to exclude from the rounding procedure.
This can be either a number or regular expression.}
}
\value{
\code{matrix/data.frame}
}
\description{
If you provide a string value in X the function will try to round this if
a numeric text is present. If you want to skip certain rows/columns then
use the excl.* arguments.
}
\examples{
mx <- matrix(c(1, 1.11, 1.25,
2.50, 2.55, 2.45,
3.2313, 3, pi),
ncol = 3, byrow=TRUE)
txtRound(mx, 1)
}
\seealso{
Other text formatters:
\code{\link{txtMergeLines}()},
\code{\link{txtPval}()}
}
\concept{text formatters}
htmlTable/man/prAttr4RgroupAdd.Rd 0000644 0001762 0000144 00000001257 13407215301 016401 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prAttr4RgroupAdd}
\alias{prAttr4RgroupAdd}
\title{Get the add attribute element}
\usage{
prAttr4RgroupAdd(rgroup, rgroup_iterator, no_cols)
}
\arguments{
\item{rgroup}{A vector of character strings containing headings for row groups.
\code{n.rgroup} must be present when \code{rgroup} is given. See
detailed description in section below.}
\item{rgroup_iterator}{The rgroup number of interest}
\item{no_cols}{The \code{ncol(x)} of the core htmlTable x argument}
}
\description{
Gets the add element attribute if it exists. If non-existant it will
return NULL.
}
\keyword{internal}
htmlTable/man/txtPval.Rd 0000644 0001762 0000144 00000003160 13572022513 014672 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/txtFrmt.R
\name{txtPval}
\alias{txtPval}
\title{Formats the p-values}
\usage{
txtPval(pvalues, lim.2dec = 10^-2, lim.sig = 10^-4, html = TRUE, ...)
}
\arguments{
\item{pvalues}{The p-values}
\item{lim.2dec}{The limit for showing two decimals. E.g.
the p-value may be 0.056 and we may want to keep the two decimals in order
to emphasize the proximity to the all-mighty 0.05 p-value and set this to
\eqn{10^-2}. This allows that a value of 0.0056 is rounded to 0.006 and this
makes intuitive sense as the 0.0056 level as this is well below
the 0.05 value and thus not as interesting to know the exact proximity to
0.05. \emph{Disclaimer:} The 0.05-limit is really silly and debated, unfortunately
it remains a standard and this package tries to adapt to the current standards in order
to limit publication associated issues.}
\item{lim.sig}{The significance limit for the less than sign, i.e. the '<'}
\item{html}{If the less than sign should be < or <
as needed for html output.}
\item{...}{Currently only used for generating warnings of deprecated call
parameters.}
}
\value{
vector
}
\description{
Gets formatted p-values. For instance
you often want 0.1234 to be 0.12 while also
having two values up until a limit,
i.e. 0.01234 should be 0.012 while
0.001234 should be 0.001. Furthermore you
want to have < 0.001 as it becomes ridiculous
to report anything below that value.
}
\examples{
txtPval(c(0.10234,0.010234, 0.0010234, 0.000010234))
}
\seealso{
Other text formatters:
\code{\link{txtMergeLines}()},
\code{\link{txtRound}()}
}
\concept{text formatters}
htmlTable/man/htmlTable.Rd 0000644 0001762 0000144 00000052363 13572022513 015155 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable.R
\name{htmlTable}
\alias{htmlTable}
\alias{htmlTable.default}
\alias{knit_print.htmlTable}
\alias{print.htmlTable}
\title{Outputting HTML tables}
\usage{
htmlTable(x, ...)
\method{htmlTable}{default}(
x,
header,
rnames,
rowlabel,
caption,
tfoot,
label,
rgroup,
n.rgroup,
cgroup,
n.cgroup,
tspanner,
n.tspanner,
total,
align = paste(rep("c", ncol(x)), collapse = ""),
align.header = paste(rep("c", ncol(x)), collapse = ""),
align.cgroup,
css.rgroup = "font-weight: 900;",
css.rgroup.sep = "",
css.tspanner = "font-weight: 900; text-align: left;",
css.tspanner.sep = "border-top: 1px solid #BEBEBE;",
css.total = "border-top: 1px solid #BEBEBE; font-weight: 900;",
css.cell = "",
css.cgroup = "",
css.class = "gmisc_table",
css.table = "margin-top: 1em; margin-bottom: 1em;",
pos.rowlabel = "bottom",
pos.caption = "top",
col.rgroup = "none",
col.columns = "none",
padding.rgroup = " ",
padding.tspanner = "",
ctable = TRUE,
compatibility = getOption("htmlTableCompat", "LibreOffice"),
cspan.rgroup = "all",
escape.html = FALSE,
...
)
\method{knit_print}{htmlTable}(x, ...)
\method{print}{htmlTable}(x, useViewer, ...)
}
\arguments{
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
\item{...}{Passed on to \code{print.htmlTable} function and any argument except the
\code{useViewer} will be passed on to the \code{\link[base]{cat}} functions arguments.}
\item{header}{A vector of character strings specifying column
header, defaulting to \code{\link[base]{colnames}(x)}}
\item{rnames}{Default rownames are generated from \code{\link[base]{rownames}(x)}. If you
provide \code{FALSE} then it will skip the rownames. \emph{Note:} For \code{data.frames}
if you do \code{\link[base]{rownames}(my_dataframe) <- NULL} it still has
rownames. Thus you need to use \code{FALSE} if you want to
surpress rownames for \code{data.frames}.}
\item{rowlabel}{If the table has rownames or \code{rnames},
rowlabel is a character string containing the
column heading for the \code{rnames}.}
\item{caption}{Adds a table caption.}
\item{tfoot}{Adds a table footer (uses the \code{} html element). The
output is run through \code{\link{txtMergeLines}} simplifying the generation
of multiple lines.}
\item{label}{A text string representing a symbolic label for the
table for referencing as an anchor. All you need to do is to reference the
table, for instance \code{see table 2}. This is
known as the element's id attribute, i.e. table id, in HTML linguo, and should
be unique id for an HTML element in contrast to the \code{css.class} element attribute.}
\item{rgroup}{A vector of character strings containing headings for row groups.
\code{n.rgroup} must be present when \code{rgroup} is given. See
detailed description in section below.}
\item{n.rgroup}{An integer vector giving the number of rows in each grouping. If \code{rgroup}
is not specified, \code{n.rgroup} is just used to divide off blocks of rows by horizontal
lines. If \code{rgroup} is given but \code{n.rgroup} is omitted, \code{n.rgroup} will
default so that each row group contains the same number of rows. If you want additional
rgroup column elements to the cells you can sett the "add" attribute to \code{rgroup} through
\code{attr(rgroup, "add")}, see below explaining section.}
\item{cgroup}{A vector, matrix or list of character strings defining major column header. The default
is to have none. These elements are also known as \emph{column spanners}. If you want a column \emph{not}
to have a spanner then put that column as "". If you pass cgroup and \code{n.crgroup} as
matrices you can have column spanners for several rows. See cgroup section below for details.}
\item{n.cgroup}{An integer vector, matrix or list containing the number of columns for which each element in
cgroup is a heading. For example, specify \code{cgroup=c("Major_1","Major_2")},
\code{n.cgroup=c(3,3)} if \code{"Major_1"} is to span columns 1-3 and
\code{"Major_2"} is to span columns 4-6.
\code{rowlabel} does not count in the column numbers. You can omit \code{n.cgroup}
if all groups have the same number of columns. If the n.cgroup is one less than
the number of columns in the matrix/data.frame then it automatically adds those.}
\item{tspanner}{The table spanner is somewhat of a table header that
you can use when you want to join different tables with the same columns.}
\item{n.tspanner}{An integer vector with the number of rows or rgroups in the original
matrix that the table spanner should span. If you have provided one fewer n.tspanner elements
the last will be imputed from the number of rgroups (if you have provided `rgroup` and
`sum(n.tspanner) < length(rgroup)`) or the number of rows in the table.}
\item{total}{The last row is sometimes a row total with a border on top and
bold fonts. Set this to \code{TRUE} if you are interested in such a row. If you
want a total row at the end of each table spanner you can set this to \code{"tspanner"}.}
\item{align}{A character strings specifying column alignments, defaulting to
\code{\link[base]{paste}(rep('c',ncol(x)),collapse='')} to center. Valid alignments are
l = left, c = center and r = right. You can also specify \code{align='c|c'} and
other LaTeX tabular formatting. If you want to set the alignment of the
rownames this string needst to be \code{ncol(x) + 1}, otherwise it automatically
pads the string with a left alignment for the rownames.}
\item{align.header}{A character strings specifying alignment for column header,
defaulting to centered, i.e. \code{\link[base]{paste}(rep('c',ncol(x)),collapse='')}.}
\item{align.cgroup}{The justification of the \code{cgroups}}
\item{css.rgroup}{CSS style for the rgorup, if different styles are wanted for each of the
rgroups you can just specify a vector with the number of elements}
\item{css.rgroup.sep}{The line between different rgroups. The line is set to the TR element
of the lower rgroup, i.e. you have to set the border-top/padding-top etc to a line with
the expected function. This is only used for rgroups that are printed. You can specify
different separators if you give a vector of rgroup - 1 length (this is since the first
rgroup doesn't have a separator).}
\item{css.tspanner}{The CSS style for the table spanner}
\item{css.tspanner.sep}{The line between different spanners}
\item{css.total}{The css of the total row}
\item{css.cell}{The css.cell element allows you to add any possible CSS style to your
table cells. See section below for details.}
\item{css.cgroup}{The same as \code{css.class} but for cgroup formatting.}
\item{css.class}{The html CSS class for the table. This allows directing html
formatting through \href{http://www.w3schools.com/Css/}{CSS}
directly at all instances of that class. \emph{Note:} unfortunately the
CSS is frequently ignored by word processors. This option
is mostly inteded for web-presentations.}
\item{css.table}{You can specify the the style of the table-element using this parameter}
\item{pos.rowlabel}{Where the rowlabel should be positioned. This value can be \code{"top"},
\code{"bottom"}, \code{"header"}, or a integer between \code{1} and \code{nrow(cgroup) + 1}. The options
\code{"bottom"} and \code{"header"} are the same, where the row label is presented at the same level as
the header.}
\item{pos.caption}{Set to \code{"bottom"} to position a caption below the table
instead of the default of \code{"top"}.}
\item{col.rgroup}{Alternating colors (zebra striping/banded rows) for each \code{rgroup}; one or two colors
is recommended and will be recycled.}
\item{col.columns}{Alternating colors for each column.}
\item{padding.rgroup}{Generally two non-breakings spaces, i.e. \code{ }, but some
journals only have a bold face for the rgroup and leaves the subelements unindented.}
\item{padding.tspanner}{The table spanner is usually without padding but you may specify padding
similar to \code{padding.rgroup} and it will be added to all elements, including the rgroup elements.
This allows for a 3-level hierarchy if needed.}
\item{ctable}{If the table should have a double top border or a single a' la LaTeX ctable style}
\item{compatibility}{Is default set to \code{LibreOffice} as some
settings need to be in old html format as Libre Office can't
handle some commands such as the css caption-alignment. Note: this
option is not yet fully implemented for all details, in the future
I aim to generate a html-correct table and one that is aimed
at Libre Office compatibility. Word-compatibility is difficult as
Word ignores most settings and destroys all layout attempts
(at least that is how my 2010 version behaves). You can additinally use the
\code{options(htmlTableCompat = "html")} if you want a change to apply
to the entire document.
MS Excel sometimes misinterprets certain cell data when opening HTML-tables (eg. 1/2 becomes 1. February).
To avoid this please specify the correct Microsoft Office format for each cell in the table using the css.cell-argument.
To make MS Excel interpret everything as text use "mso-number-format:\"\\@\"".}
\item{cspan.rgroup}{The number of columns that an \code{rgroup} should span. It spans
by default all columns but you may want to limit this if you have column colors
that you want to retain.}
\item{escape.html}{logical: should HTML characters be escaped? Defaults to FALSE.}
\item{useViewer}{If you are using RStudio there is a viewer thar can render
the table within that is envoced if in \code{\link[base]{interactive}} mode.
Set this to \code{FALSE} if you want to remove that functionality. You can
also force the function to call a specific viewer by setting this to a
viewer function, e.g. \code{useViewer = utils::browseURL} if you want to
override the default RStudio viewer. Another option that does the same is to
set the \code{options(viewer=utils::browseURL)} and it will default to that
particular viewer (this is how RStudio decides on a viewer).
\emph{Note:} If you want to force all output to go through the
\code{\link[base]{cat}()} the set \code{\link[base]{options}(htmlTable.cat = TRUE)}.}
}
\value{
\code{string} Returns a string of class htmlTable
}
\description{
This is a function for outputting a more advanced
table than what \pkg{xtable}, \pkg{ztable}, or \pkg{knitr}'s
\code{\link[knitr]{kable}()} allows.
It's aim is to provide the \pkg{Hmisc} \code{\link[Hmisc]{latex}()}
colgroup and rowgroup functions in HTML. The html-output is designed for
maximum compatibility with LibreOffice/OpenOffice.
}
\section{Multiple rows of column spanners \code{cgroup}}{
If you want to have a column spanner in multiple levels you can
set the \code{cgroup} and \code{n.cgroup} arguments to a \code{matrix} or
\code{list}.
If the different levels have different number of elements and you have
provided a **matrix** you need to set the ones that lack elements to NA. For instance
\code{cgroup = rbind(c("first", "second", NA), c("a", "b", "c"))}.
And the corresponding n,cgroup would be \code{n.cgroup = rbind(c(1, 2, NA), c(2, 1, 2))}.
for a table consisting of 5 columns. The "first" spans the first two columns,
the "second" spans the last three columns, "a" spans the first two, "b"
the middle column, and "c" the last two columns.
It is recommended to use `list` as you will not have to bother with the `NA`.
If you want leav a cgroup empty then simply provide `""` as the cgroup.
}
\section{The \code{rgroup} argument}{
The rgroup allows you to smoothly group rows. Each row within a group
receives an indention of two blank spaces and are grouped with their
corresponing rgroup element. The \code{sum(n.rgroup)} should always
be equal or less than the matrix rows. If less then it will pad the
remaining rows with either an empty rgroup, i.e. an "" or if the
rgroup is one longer than the n.rgroup the last n.rgroup element will
be calculated through \code{nrow(x) - sum(n.rgroup)} in order to make
the table generating smoother.
}
\section{The add attribute to \code{rgroup}}{
You can now have an additional element at the rgroup level by specifying the
\code{attr(rgroup, 'add')}. The value can either be a \code{vector}, a \code{list},
or a \code{matrix}. See \code{vignette("general", package = "htmlTable")} for examples.
\itemize{
\item{A \code{vector} of either equal number of rgroups to the number
of rgroups that aren't empty, i.e. \code{rgroup[rgroup != ""]}. Or a named vector where
the name must correspond to either an rgroup or to an rgroup number.}
\item{A \code{list} that has exactly the same requirements as the vector.
In addition to the previous we can also have a list with column numbers within
as names within the list.}
\item{A \code{matrix} with the dimensiont \code{nrow(x) x ncol(x)} or
\code{nrow(x) x 1} where the latter is equivalent to a named vector.
If you have \code{rownames} these will resolve similarly to the names to the
\code{list}/\code{vector} arguments. The same thing applies to \code{colnames}.
}
}
}
\section{Important \pkg{knitr}-note}{
This funciton will only work with \pkg{knitr} outputting \emph{html}, i.e.
markdown mode. As the function returns raw html-code
the compatibility with non-html formatting is limited,
even with \href{http://johnmacfarlane.net/pandoc/}{pandoc}.
Thanks to the the \code{\link[knitr]{knit_print}} and the
\code{\link[knitr]{asis_output}}
the \code{results='asis'} is \emph{no longer needed} except within for-loops.
If you have a knitr-chunk with a for loop and use \code{print()} to produce
raw html you must set the chunk option \code{results='asis'}. \code{Note}:
the print-function relies on the \code{\link[base]{interactive}()} function
for determining if the output should be sent to a browser or to the terminal.
In vignettes and other directly knitted documents you may need to either set
\code{useViewer = FALSE} alternatively set \code{options(htmlTable.cat = TRUE)}.
}
\section{RStudio's notebook}{
RStudio has an interactive notebook that allows output directly into the document.
In order for the output to be properly formatted it needs to have the \code{class}
of \code{html}. The \code{htmlTable} tries to identify if the environment is a
notebook document (uses the rstudio api and identifies if its a file with and `Rmd`
file ending or if ther is an element with `html_notebook`). If you don't want this
behaviour you can remove it using the `options(htmlTable.skip_notebook = TRUE)`
}
\section{Table counter}{
If you set the option table_counter you will get a Table 1,2,3
etc before each table, just set \code{options(table_counter=TRUE)}. If
you set it to a number then that number will correspond to the start of
the table_counter. The \code{table_counter} option will also contain the number
of the last table, this can be useful when referencing it in text. By
setting the option \code{options(table_counter_str = "Table \%s: ")}
you can manipulate the counter table text that is added prior to the
actual caption. Note, you should use the \code{\link{sprintf}} \code{\%s}
instead of \code{\%d} as the software converts all numbers to characters
for compatibility reasons. If you set \code{options(table_counter_roman = TRUE)}
then the table counter will use Roman numumerals instead of Arabic.
}
\section{The \code{css.cell} argument}{
The \code{css.cell} parameter allows you to add any possible CSS style
to your table cells. \code{css.cell} can be either a vector or a matrix.
If \code{css.cell} is a \emph{vector}, it's assumed that the styles should be repeated
throughout the rows (that is, each element in css.cell specifies the style
for a whole column of 'x').
In the case of \code{css.cell} being a \emph{matrix} of the same size of the \code{x} argument,
each element of \code{x} gets the style from the corresponding element in css.cell. Additionally,
the number of rows of \code{css.cell} can be \code{nrow(x) + 1} so the first row of of \code{css.cell}
specifies the style for the header of \code{x}; also the number of columns of \code{css.cell}
can be \code{ncol(x) + 1} to include the specification of style for row names of \code{x}.
Note that the \code{text-align} CSS field in the \code{css.cell} argument will be overriden
by the \code{align} argument.
}
\section{Empty dataframes}{
An empty dataframe will result in a warning and output an empty table, provided that
rgroup and n.rgroup are not specified. All other row layout options will be ignored.
}
\section{Browsers and possible issues}{
\emph{Copy-pasting:} As you copy-paste results into Word you need to keep
the original formatting. Either right click and choose that paste option or click
on the icon appearing after a paste. Currently the following compatibitilies
have been tested with MS Word 2013:
\itemize{
\item{\bold{Internet Explorer} (v. 11.20.10586.0) Works perfectly when copy-pasting into Word}
\item{\bold{RStudio} (v. 0.99.448) Works perfectly when copy-pasting into Word.
\emph{Note:} can have issues with multiline cgroups -
see \href{http://code.google.com/p/chromium/issues/detail?id=305130}{bug}}
\item{\bold{Chrome} (v. 47.0.2526.106) Works perfectly when copy-pasting into Word.
\emph{Note:} can have issues with multiline cgroups -
see \href{http://code.google.com/p/chromium/issues/detail?id=305130}{bug}}
\item{\bold{Firefox} (v. 43.0.3) Works poorly - looses font-styling, lines and general feel}
\item{\bold{Edge} (v. 25.10586.0.0) Works poorly - looses lines and general feel}
}
\emph{Direct word processor opening:} Opening directly in LibreOffice or Word is no longer
recommended. You get much prettier results using the cut-and-paste option.
Note that when using complex cgroup alignments with multiple levels
not every browser is able to handle this. For instance the RStudio
webkit browser seems to have issues with this and a
\href{http://code.google.com/p/chromium/issues/detail?id=305130}{bug has been filed}.
As the table uses html for rendering you need to be aware of that headers,
rownames, and cell values should try respect this for optimal display. Browsers
try to compensate and frequently the tables still turn out fine but it is
not advized. Most importantly you should try to use
\code{<} instead of \code{<} and
\code{>} instead of \code{>}. You can find a complete list
of html characters \href{http://ascii.cl/htmlcodes.htm}{here}.
}
\examples{
# Store all output into a list in order to
# output everything at once at the end
all_tables <- list()
# A simple output
output <- matrix(1:4,
ncol=2,
dimnames = list(list("Row 1", "Row 2"),
list("Column 1", "Column 2")))
htmlTable(output) ->
all_tables[["Basic table"]]
# An advanced output
output <-
matrix(ncol=6, nrow=8)
for (nr in 1:nrow(output)){
for (nc in 1:ncol(output)){
output[nr, nc] <-
paste0(nr, ":", nc)
}
}
htmlTable(output, align="r",
header = paste(c("1st", "2nd",
"3rd", "4th",
"5th", "6th"),
"hdr"),
rnames = paste(c("1st", "2nd",
"3rd",
paste0(4:8, "th")),
"row"),
rgroup = paste("Group", LETTERS[1:3]),
n.rgroup = c(2,4,nrow(output) - 6),
cgroup = rbind(c("", "Column spanners", NA),
c("", "Cgroup 1", "Cgroup 2†")),
n.cgroup = rbind(c(1,2,NA),
c(2,2,2)),
caption="Basic table with both column spanners (groups) and row groups",
tfoot="† A table footer commment",
cspan.rgroup = 2,
col.columns = c(rep("none", 2),
rep("#F5FBFF", 4)),
col.rgroup = c("none", "#F7F7F7"),
css.cell = "padding-left: .5em; padding-right: .2em;") ->
all_tables[["Advanced table"]]
# An advanced empty table
output <- matrix(ncol = 6,
nrow = 0)
htmlTable(output, align="r",
header = paste(c("1st", "2nd",
"3rd", "4th",
"5th", "6th"),
"hdr"),
cgroup = rbind(c("", "Column spanners", NA),
c("", "Cgroup 1", "Cgroup 2†")),
n.cgroup = rbind(c(1,2,NA),
c(2,2,2)),
caption="Basic empty table with column spanners (groups) and ignored row colors",
tfoot="† A table footer commment",
cspan.rgroup = 2,
col.columns = c(rep("none", 2),
rep("#F5FBFF", 4)),
col.rgroup = c("none", "#F7F7F7"),
css.cell = "padding-left: .5em; padding-right: .2em;") ->
all_tables[["Empty table"]]
# An example of how to use the css.cell for header styling
simple_output <- matrix(1:4, ncol=2)
htmlTable(simple_output,
header = LETTERS[1:2],
css.cell = rbind(rep("background: lightgrey; font-size: 2em;", times=ncol(simple_output)),
matrix("", ncol=ncol(simple_output), nrow=nrow(simple_output)))) ->
all_tables[["Header formatting"]]
concatHtmlTables(all_tables)
# See vignette("tables", package = "htmlTable")
# for more examples
}
\seealso{
\code{\link{txtMergeLines}},
\code{\link[Hmisc]{latex}}
Other table functions:
\code{\link{tblNoLast}()},
\code{\link{tblNoNext}()}
}
\concept{table functions}
htmlTable/man/prGetRowlabelPos.Rd 0000644 0001762 0000144 00000003104 13572022513 016461 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prGetRowlabelPos}
\alias{prGetRowlabelPos}
\title{Gets the rowlabel position}
\usage{
prGetRowlabelPos(cgroup, pos.rowlabel, header)
}
\arguments{
\item{cgroup}{A vector, matrix or list of character strings defining major column header. The default
is to have none. These elements are also known as \emph{column spanners}. If you want a column \emph{not}
to have a spanner then put that column as "". If you pass cgroup and \code{n.crgroup} as
matrices you can have column spanners for several rows. See cgroup section below for details.}
\item{pos.rowlabel}{Where the rowlabel should be positioned. This value can be \code{"top"},
\code{"bottom"}, \code{"header"}, or a integer between \code{1} and \code{nrow(cgroup) + 1}. The options
\code{"bottom"} and \code{"header"} are the same, where the row label is presented at the same level as
the header.}
\item{header}{A vector of character strings specifying column
header, defaulting to \code{\link[base]{colnames}(x)}}
}
\value{
\code{integer} Returns the position within the header rows
to print the \code{rowlabel} argument
}
\description{
Gets the rowlabel position
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddCells}()},
\code{\link{prAddSemicolon2StrEnd}()},
\code{\link{prEscapeHtml}()},
\code{\link{prGetCgroupHeader}()},
\code{\link{prGetStyle}()},
\code{\link{prPrepareAlign}()},
\code{\link{prPrepareCgroup}()},
\code{\link{prTblNo}()}
}
\concept{hidden helper functions for htmlTable}
\keyword{internal}
htmlTable/man/pvalueFormatter.Rd 0000644 0001762 0000144 00000000721 13407215301 016404 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/deprecated.R
\name{pvalueFormatter}
\alias{pvalueFormatter}
\title{Deprecated use \code{\link{txtPval}} instead}
\usage{
pvalueFormatter(...)
}
\arguments{
\item{...}{Currently only used for generating warnings of deprecated call}
}
\description{
Deprecated use \code{\link{txtPval}} instead
}
\examples{
pvalueFormatter(c(0.10234,0.010234, 0.0010234, 0.000010234))
}
\keyword{internal}
htmlTable/man/SCB.Rd 0000644 0001762 0000144 00000002730 13407215301 013635 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data-SCB.R
\docType{data}
\name{SCB}
\alias{SCB}
\title{Average age in Sweden}
\description{
For the vignettes there is a dataset downloaded by using the
\code{get_pxweb_data()} call. The data is from
SCB (\href{http://scb.se/}{Statistics Sweden}) and downloaded
using the \href{https://github.com/rOpenGov/pxweb}{pxweb package}:
}
\examples{
\dontrun{
# The data was generated through downloading via the API
library(pxweb)
# Get the last 15 years of data (the data always lags 1 year)
current_year <- as.integer(format(Sys.Date(), "\%Y")) -1
SCB <- get_pxweb_data(
url = "http://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101B/BefolkningMedelAlder",
dims = list(Region = c('00', '01', '03', '25'),
Kon = c('1', '2'),
ContentsCode = c('BE0101G9'),
Tid = (current_year-14):current_year),
clean = TRUE)
# Some cleaning was needed before use
SCB$region <- factor(substring(as.character(SCB$region), 4))
Swe_ltrs <- c("å" = "å",
"Å" = "Å",
"ä" = "ä",
"Ä" = "Ä",
"ö" = "ö",
"Ö" = "Ö")
for (i in 1:length(Swe_ltrs)){
levels(SCB$region) <- gsub(names(Swe_ltrs)[i],
Swe_ltrs[i],
levels(SCB$region))
}
save(SCB, file = "data/SCB.rda")
}
}
\references{
\url{http://scb.se}
}
\author{
Max Gordon \email{max@gforge.se}
}
\keyword{data}
htmlTable/man/prConvertDfFactors.Rd 0000644 0001762 0000144 00000001053 13407215301 017001 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable.R
\name{prConvertDfFactors}
\alias{prConvertDfFactors}
\title{Convert all factors to characters to print them as they expected}
\usage{
prConvertDfFactors(x)
}
\arguments{
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
}
\value{
The data frame with factors as characters
}
\description{
Convert all factors to characters to print them as they expected
}
htmlTable/man/vector2string.Rd 0000644 0001762 0000144 00000001316 13572022513 016044 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vector2string.R
\name{vector2string}
\alias{vector2string}
\title{Collapse vector to string}
\usage{
vector2string(
x,
quotation_mark = "'",
collapse = sprintf("\%s, \%s", quotation_mark, quotation_mark)
)
}
\arguments{
\item{x}{The vector to collapse}
\item{quotation_mark}{The type of quote to use}
\item{collapse}{The string that separates each element}
}
\value{
A string with \code{', '} separation
}
\description{
Merges all the values and outputs a string
formatted as '1st element', '2nd element', ...
}
\examples{
vector2string(1:4)
vector2string(c("a","b'b", "c"))
vector2string(c("a","b'b", "c"), quotation_mark = '"')
}
htmlTable/man/prGetStyle.Rd 0000644 0001762 0000144 00000002131 13572022513 015327 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prGetStyle}
\alias{prGetStyle}
\title{Gets the CSS style element}
\usage{
prGetStyle(...)
}
\arguments{
\item{...}{All styles here are merged with the first parameter.
If you provide a name, e.g. \code{styles="background: blue", align="center"}
the function will convert the \code{align} into proper \code{align: center}.}
\item{styles}{The styles can be provided as \code{vector},
\code{named vector}, or \code{string}.}
}
\value{
\code{string} Returns the codes merged into one string with
correct CSS ; and : structure.
}
\description{
A funciton for checking, merging, and more
with a variety of different style formats.
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddCells}()},
\code{\link{prAddSemicolon2StrEnd}()},
\code{\link{prEscapeHtml}()},
\code{\link{prGetCgroupHeader}()},
\code{\link{prGetRowlabelPos}()},
\code{\link{prPrepareAlign}()},
\code{\link{prPrepareCgroup}()},
\code{\link{prTblNo}()}
}
\concept{hidden helper functions for htmlTable}
\keyword{internal}
htmlTable/man/outputInt.Rd 0000644 0001762 0000144 00000000565 13407215301 015245 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/deprecated.R
\name{outputInt}
\alias{outputInt}
\title{Deprecated use \code{\link{txtInt}} instead.}
\usage{
outputInt(...)
}
\arguments{
\item{...}{Passed to \code{\link{txtInt}}}
}
\description{
Deprecated use \code{\link{txtInt}} instead.
}
\examples{
outputInt(123456)
}
\keyword{internal}
htmlTable/man/prGetRgroupLine.Rd 0000644 0001762 0000144 00000004257 13572022513 016330 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_render.R
\name{prGetRgroupLine}
\alias{prGetRgroupLine}
\title{Gets the number of rgroup htmlLine}
\usage{
prGetRgroupLine(
x,
total_columns,
rgroup,
rgroup_iterator,
cspan,
rnames,
align,
style,
cgroup_spacer_cells,
col.columns,
css.row,
padding.tspanner
)
}
\arguments{
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
\item{total_columns}{The total number of columns including the rowlabel and the
spacer cells}
\item{rgroup}{A vector of character strings containing headings for row groups.
\code{n.rgroup} must be present when \code{rgroup} is given. See
detailed description in section below.}
\item{rgroup_iterator}{An integer indicating the rgroup}
\item{cspan}{The column span of the current rgroup}
\item{rnames}{Default rownames are generated from \code{\link[base]{rownames}(x)}. If you
provide \code{FALSE} then it will skip the rownames. \emph{Note:} For \code{data.frames}
if you do \code{\link[base]{rownames}(my_dataframe) <- NULL} it still has
rownames. Thus you need to use \code{FALSE} if you want to
surpress rownames for \code{data.frames}.}
\item{align}{A character strings specifying column alignments, defaulting to
\code{\link[base]{paste}(rep('c',ncol(x)),collapse='')} to center. Valid alignments are
l = left, c = center and r = right. You can also specify \code{align='c|c'} and
other LaTeX tabular formatting. If you want to set the alignment of the
rownames this string needst to be \code{ncol(x) + 1}, otherwise it automatically
pads the string with a left alignment for the rownames.}
\item{style}{The css style corresponding to the rgroup css style that includes
the color specific for the rgroup, i.e. \code{col.rgroup}.}
\item{cgroup_spacer_cells}{The vector indicating the position of the cgroup
spacer cells}
\item{col.columns}{Alternating colors for each column.}
\item{css.row}{The css.cell information for this particular row.}
\item{padding.tspanner}{The tspanner padding}
}
\description{
Gets the number of rgroup htmlLine
}
\keyword{internal}
htmlTable/man/splitLines4Table.Rd 0000644 0001762 0000144 00000000611 13407215301 016404 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/deprecated.R
\name{splitLines4Table}
\alias{splitLines4Table}
\title{See \code{\link{txtMergeLines}}}
\usage{
splitLines4Table(...)
}
\arguments{
\item{...}{passed onto \code{\link{txtMergeLines}}}
}
\description{
See \code{\link{txtMergeLines}}
}
\examples{
splitLines4Table("hello", "world")
}
\keyword{internal}
htmlTable/man/concatHtmlTables.Rd 0000644 0001762 0000144 00000006636 13407215301 016466 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/concatHtmlTables.R
\name{concatHtmlTables}
\alias{concatHtmlTables}
\title{Funciton for concatenating htmlTables}
\usage{
concatHtmlTables(tables, headers)
}
\arguments{
\item{tables}{A list of html tables to be concatenated}
\item{headers}{Either a string or a vector of strings that function as
a header for each table. If none is provided it will use the names of
the table list or a numeric number.}
}
\value{
htmlTable class object
}
\description{
Funciton for concatenating htmlTables
}
\examples{
# Store all output into a list in order to
# output everything at once at the end
all_tables <- list()
# A simple output
output <- matrix(1:4,
ncol=2,
dimnames = list(list("Row 1", "Row 2"),
list("Column 1", "Column 2")))
htmlTable(output) ->
all_tables[["Basic table"]]
# An advanced output
output <-
matrix(ncol=6, nrow=8)
for (nr in 1:nrow(output)){
for (nc in 1:ncol(output)){
output[nr, nc] <-
paste0(nr, ":", nc)
}
}
htmlTable(output, align="r",
header = paste(c("1st", "2nd",
"3rd", "4th",
"5th", "6th"),
"hdr"),
rnames = paste(c("1st", "2nd",
"3rd",
paste0(4:8, "th")),
"row"),
rgroup = paste("Group", LETTERS[1:3]),
n.rgroup = c(2,4,nrow(output) - 6),
cgroup = rbind(c("", "Column spanners", NA),
c("", "Cgroup 1", "Cgroup 2†")),
n.cgroup = rbind(c(1,2,NA),
c(2,2,2)),
caption="Basic table with both column spanners (groups) and row groups",
tfoot="† A table footer commment",
cspan.rgroup = 2,
col.columns = c(rep("none", 2),
rep("#F5FBFF", 4)),
col.rgroup = c("none", "#F7F7F7"),
css.cell = "padding-left: .5em; padding-right: .2em;") ->
all_tables[["Advanced table"]]
# An advanced empty table
output <- matrix(ncol = 6,
nrow = 0)
htmlTable(output, align="r",
header = paste(c("1st", "2nd",
"3rd", "4th",
"5th", "6th"),
"hdr"),
cgroup = rbind(c("", "Column spanners", NA),
c("", "Cgroup 1", "Cgroup 2†")),
n.cgroup = rbind(c(1,2,NA),
c(2,2,2)),
caption="Basic empty table with column spanners (groups) and ignored row colors",
tfoot="† A table footer commment",
cspan.rgroup = 2,
col.columns = c(rep("none", 2),
rep("#F5FBFF", 4)),
col.rgroup = c("none", "#F7F7F7"),
css.cell = "padding-left: .5em; padding-right: .2em;") ->
all_tables[["Empty table"]]
# An example of how to use the css.cell for header styling
simple_output <- matrix(1:4, ncol=2)
htmlTable(simple_output,
header = LETTERS[1:2],
css.cell = rbind(rep("background: lightgrey; font-size: 2em;", times=ncol(simple_output)),
matrix("", ncol=ncol(simple_output), nrow=nrow(simple_output)))) ->
all_tables[["Header formatting"]]
concatHtmlTables(all_tables)
# See vignette("tables", package = "htmlTable")
# for more examples
}
htmlTable/man/tidyHtmlTable.Rd 0000644 0001762 0000144 00000010775 13572022513 016010 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidyHtmlTable.R
\name{tidyHtmlTable}
\alias{tidyHtmlTable}
\title{Generate an htmlTable using a ggplot2-like interface}
\usage{
tidyHtmlTable(
x,
value = "value",
header = "header",
rnames = "rnames",
rgroup = NULL,
hidden_rgroup = NULL,
cgroup1 = NULL,
cgroup2 = NULL,
tspanner = NULL,
hidden_tspanner = NULL,
...
)
}
\arguments{
\item{x}{Tidy data used to build the \code{htmlTable}}
\item{value}{The column containing values filling individual cells of the
output \code{htmlTable}}
\item{header}{The column in \code{x} specifying column headings}
\item{rnames}{The column in \code{x} specifying row names}
\item{rgroup}{The column in \code{x} specifying row groups}
\item{hidden_rgroup}{rgroup values that will be hidden.}
\item{cgroup1}{The column in \code{x} specifying the inner most column
groups}
\item{cgroup2}{The column in \code{x} specifying the outer most column
groups}
\item{tspanner}{The column in \code{x} specifying tspanner groups}
\item{hidden_tspanner}{tspanner values that will be hidden.}
\item{...}{Additional arguments that will be passed to the inner
\code{htmlTable} function}
}
\value{
Returns html code that will build a pretty table
}
\description{
Builds an \code{htmlTable} by mapping columns from the input data, \code{x},
to elements of an output \code{htmlTable} (e.g. rnames, header, etc.)
}
\section{Column-mapping parameters}{
The \code{tidyHtmlTable} function is designed to work like ggplot2 in that
columns from \code{x} are mapped to specific parameters from the
\code{htmlTable} function. At minimum, \code{x} must contain the names
of columns mapping to \code{rnames}, \code{header}, and \code{rnames}.
\code{header} and \code{rnames} retain the same meaning as in the
htmlTable function. \code{value} contains the individual values that will
be used to fill each cell within the output \code{htmlTable}.
A full list of parameters from \code{htmlTable} which may be mapped to
columns within \code{x} include:
\itemize{
\item \code{value}
\item \code{header}
\item \code{rnames}
\item \code{rgroup}
\item \code{cgroup1}
\item \code{cgroup2}
\item \code{tspanner}
}
Note that unlike in \code{htmlTable} which contains \code{cgroup},
and which may specify a variable number of column groups,
\code{tidyhtmlTable} contains the parameters \code{cgroup1} and
\code{cgroup2}. These parameters correspond to the inward most and outward
most column groups respectively.
Also note that the coordinates of each \code{value} within \code{x} must be
unambiguously mapped to a position within the output \code{htmlTable}.
Therefore, the each row-wise combination the variables specified above
contained in \code{x} must be unique.
}
\section{Hidden values}{
\code{htmlTable} Allows for some values within \code{rgroup},
\code{cgroup}, etc. to be specified as \code{""}. The following parameters
allow for specific values to be treated as if they were a string of length
zero in the \code{htmlTable} function.
\itemize{
\item \code{hidden_rgroup}
\item \code{hidden_tspanner}
}
}
\section{Additional dependencies}{
In order to run this function you also must have \code{\link[dplyr]{dplyr}} and
\code{\link[tidyr]{tidyr}} packages installed. These have been removed due to
the additional 20 Mb that these dependencies added (issue #47). The particular
functions required are:
\itemize{
\item \code{\link[dplyr]{dplyr}}:
\code{mutate_at},
\code{select},
\code{pull},
\code{slice},
\code{filter},
\code{arrange_at},
\code{mutate_if},
\code{is.grouped_df},
\code{left_join}
\item \code{\link[tidyr]{tidyr}}: \code{spread}
}
}
\examples{
\dontrun{
library(tidyverse)
mtcars \%>\%
rownames_to_column \%>\%
select(rowname, cyl, gear, hp, mpg, qsec) \%>\%
gather(per_metric, value, hp, mpg, qsec) \%>\%
group_by(cyl, gear, per_metric) \%>\%
summarise(Mean = round(mean(value), 1),
SD = round(sd(value), 1),
Min = round(min(value), 1),
Max = round(max(value), 1)) \%>\%
gather(summary_stat, value, Mean, SD, Min, Max) \%>\%
ungroup \%>\%
mutate(gear = paste(gear, "Gears"),
cyl = paste(cyl, "Cylinders")) \%>\%
tidyHtmlTable(header = "gear",
cgroup1 = "cyl",
cell_value = "value",
rnames = "summary_stat",
rgroup = "per_metric")
}
}
\seealso{
\code{\link{htmlTable}}
}
htmlTable/man/prGetScriptString.Rd 0000644 0001762 0000144 00000000671 13407215301 016665 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/interactiveTable.R
\name{prGetScriptString}
\alias{prGetScriptString}
\title{Gets a string with all the scripts merged into one script tag}
\usage{
prGetScriptString(x)
}
\arguments{
\item{x}{An interactiveTable}
}
\value{
string
}
\description{
Each element has it's own script tags in otherwise an error will cause
all the scripts to fail.
}
\keyword{internal}
htmlTable/man/interactiveTable.Rd 0000644 0001762 0000144 00000006053 13572022513 016521 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/interactiveTable.R
\name{interactiveTable}
\alias{interactiveTable}
\alias{interactiveTable.htmlTable}
\alias{knit_print.interactiveTable}
\alias{print.interactiveTable}
\title{An interactive table that allows you to limit the size of boxes}
\usage{
interactiveTable(
x,
...,
txt.maxlen = 20,
button = FALSE,
minimized.columns,
js.scripts = c()
)
\method{interactiveTable}{htmlTable}(
tbl,
txt.maxlen = 20,
button = FALSE,
minimized.columns,
js.scripts = c()
)
\method{knit_print}{interactiveTable}(x, ...)
\method{print}{interactiveTable}(x, useViewer, ...)
}
\arguments{
\item{x}{The interactive table that is to be printed}
\item{...}{The exact same parameters as \code{\link{htmlTable}} uses}
\item{txt.maxlen}{The maximum length of a text}
\item{button}{Indicator if the cell should be clickable or if a button should appear with a plus/minus}
\item{minimized.columns}{Notifies if any particular columns should be collapsed from start}
\item{js.scripts}{If you want to add your own JavaScript code you can just add it here.
All code is merged into one string where each section is wrapped in it's own
\code{} element.}
\item{tbl}{An htmlTable object can be directly passed into the function}
\item{useViewer}{If you are using RStudio there is a viewer thar can render
the table within that is envoced if in \code{\link[base]{interactive}} mode.
Set this to \code{FALSE} if you want to remove that functionality. You can
also force the function to call a specific viewer by setting this to a
viewer function, e.g. \code{useViewer = utils::browseURL} if you want to
override the default RStudio viewer. Another option that does the same is to
set the \code{options(viewer=utils::browseURL)} and it will default to that
particular viewer (this is how RStudio decides on a viewer).
\emph{Note:} If you want to force all output to go through the
\code{\link[base]{cat}()} the set \code{\link[base]{options}(htmlTable.cat = TRUE)}.}
}
\value{
An htmlTable with a javascript attribute containing the code that is then printed
}
\description{
This function wraps the htmlTable and adds JavaScript code for toggling the amount
of text shown in any particular cell.
}
\examples{
# A simple output
long_txt <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum"
short_txt <- gsub("(^[^.]+).*", "\\\\1", long_txt)
output <-
cbind(rep(short_txt, 2),
rep(long_txt, 2))
interactiveTable(output,
minimized.columns = ncol(output),
header = c("Short", "Long"),
rnames = c("First", "Second"),
col.rgroup = c("#FFF", "#EEF"))
}
htmlTable/man/prSkipRownames.Rd 0000644 0001762 0000144 00000001274 13407215301 016214 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prSkipRownames}
\alias{prSkipRownames}
\title{Returns if rownames should be printed for the htmlTable}
\usage{
prSkipRownames(rnames)
}
\arguments{
\item{rnames}{Default rownames are generated from \code{\link[base]{rownames}(x)}. If you
provide \code{FALSE} then it will skip the rownames. \emph{Note:} For \code{data.frames}
if you do \code{\link[base]{rownames}(my_dataframe) <- NULL} it still has
rownames. Thus you need to use \code{FALSE} if you want to
surpress rownames for \code{data.frames}.}
}
\description{
Returns if rownames should be printed for the htmlTable
}
\keyword{internal}
htmlTable/man/prAddCells.Rd 0000644 0001762 0000144 00000003702 13572022513 015247 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prAddCells}
\alias{prAddCells}
\title{Add a cell}
\usage{
prAddCells(
rowcells,
cellcode,
align,
style,
cgroup_spacer_cells,
has_rn_col,
col.columns,
offset = 1,
css.cell
)
}
\arguments{
\item{rowcells}{The cells with the values that are to be added}
\item{cellcode}{Type of cell, can either be \code{th} or \code{td}}
\item{align}{A character strings specifying column alignments, defaulting to
\code{\link[base]{paste}(rep('c',ncol(x)),collapse='')} to center. Valid alignments are
l = left, c = center and r = right. You can also specify \code{align='c|c'} and
other LaTeX tabular formatting. If you want to set the alignment of the
rownames this string needst to be \code{ncol(x) + 1}, otherwise it automatically
pads the string with a left alignment for the rownames.}
\item{style}{The cell style}
\item{cgroup_spacer_cells}{The number of cells that occur between
columns due to the cgroup arguments.}
\item{has_rn_col}{Due to the alignment issue we need to keep track
of if there has already been printed a rowname column or not and therefore
we have this has_rn_col that is either 0 or 1.}
\item{col.columns}{Alternating colors for each column.}
\item{offset}{For rgroup rows there may be an offset != 1}
\item{css.cell}{The css.cell but only for this row compared to the htmlTable matrix}
}
\value{
\code{string} Returns the string with the new cell elements
}
\description{
Adds a row of cells val | ... | to a table string for
\code{\link{htmlTable}}
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddSemicolon2StrEnd}()},
\code{\link{prEscapeHtml}()},
\code{\link{prGetCgroupHeader}()},
\code{\link{prGetRowlabelPos}()},
\code{\link{prGetStyle}()},
\code{\link{prPrepareAlign}()},
\code{\link{prPrepareCgroup}()},
\code{\link{prTblNo}()}
}
\concept{hidden helper functions for htmlTable}
\keyword{internal}
htmlTable/man/prPrepareCss.Rd 0000644 0001762 0000144 00000002123 13407215301 015633 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prPrepareCss}
\alias{prPrepareCss}
\title{Prepares the cell style}
\usage{
prPrepareCss(x, css, rnames, header, name = deparse(substitute(css)))
}
\arguments{
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
\item{css}{The CSS styles that are to be converted into
a matrix.}
\item{rnames}{Default rownames are generated from \code{\link[base]{rownames}(x)}. If you
provide \code{FALSE} then it will skip the rownames. \emph{Note:} For \code{data.frames}
if you do \code{\link[base]{rownames}(my_dataframe) <- NULL} it still has
rownames. Thus you need to use \code{FALSE} if you want to
surpress rownames for \code{data.frames}.}
\item{header}{A vector of character strings specifying column
header, defaulting to \code{\link[base]{colnames}(x)}}
\item{name}{The name of the CSS style that is prepared}
}
\value{
\code{matrix}
}
\description{
Prepares the cell style
}
\keyword{internal}
htmlTable/man/txtInt.Rd 0000644 0001762 0000144 00000001550 13412664215 014527 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/txtFrmt.R
\name{txtInt}
\alias{txtInt}
\title{SI or English formatting of an integer}
\usage{
txtInt(x, language = "en", html = TRUE, ...)
}
\arguments{
\item{x}{The integer variable}
\item{language}{The ISO-639-1 two-letter code for the language of
interest. Currently only english is distinguished from the ISO
format using a ',' as the separator.}
\item{html}{If the format is used in html context
then the space should be a non-breaking space, \code{ }}
\item{...}{Passed to \code{\link[base]{format}}}
}
\value{
\code{string}
}
\description{
English uses ',' between every 3 numbers while the
SI format recommends a ' ' if x > 10^4. The scientific
form 10e+? is furthermore avoided.
}
\examples{
txtInt(123)
txtInt(1234)
txtInt(12345)
txtInt(123456)
}
\concept{text formatters#'}
htmlTable/man/prGetThead.Rd 0000644 0001762 0000144 00000011105 13572022513 015255 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_render.R
\name{prGetThead}
\alias{prGetThead}
\title{Renders the table head (thead)}
\usage{
prGetThead(
x,
header,
cgroup,
n.cgroup,
caption,
pos.caption,
compatibility,
total_columns,
align.cgroup,
css.cgroup,
top_row_style,
rnames,
rowlabel,
pos.rowlabel,
cgroup_spacer_cells,
css.cell,
align.header,
cell_style
)
}
\arguments{
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
\item{header}{A vector of character strings specifying column
header, defaulting to \code{\link[base]{colnames}(x)}}
\item{cgroup}{A vector, matrix or list of character strings defining major column header. The default
is to have none. These elements are also known as \emph{column spanners}. If you want a column \emph{not}
to have a spanner then put that column as "". If you pass cgroup and \code{n.crgroup} as
matrices you can have column spanners for several rows. See cgroup section below for details.}
\item{n.cgroup}{An integer vector, matrix or list containing the number of columns for which each element in
cgroup is a heading. For example, specify \code{cgroup=c("Major_1","Major_2")},
\code{n.cgroup=c(3,3)} if \code{"Major_1"} is to span columns 1-3 and
\code{"Major_2"} is to span columns 4-6.
\code{rowlabel} does not count in the column numbers. You can omit \code{n.cgroup}
if all groups have the same number of columns. If the n.cgroup is one less than
the number of columns in the matrix/data.frame then it automatically adds those.}
\item{caption}{Adds a table caption.}
\item{pos.caption}{Set to \code{"bottom"} to position a caption below the table
instead of the default of \code{"top"}.}
\item{compatibility}{Is default set to \code{LibreOffice} as some
settings need to be in old html format as Libre Office can't
handle some commands such as the css caption-alignment. Note: this
option is not yet fully implemented for all details, in the future
I aim to generate a html-correct table and one that is aimed
at Libre Office compatibility. Word-compatibility is difficult as
Word ignores most settings and destroys all layout attempts
(at least that is how my 2010 version behaves). You can additinally use the
\code{options(htmlTableCompat = "html")} if you want a change to apply
to the entire document.
MS Excel sometimes misinterprets certain cell data when opening HTML-tables (eg. 1/2 becomes 1. February).
To avoid this please specify the correct Microsoft Office format for each cell in the table using the css.cell-argument.
To make MS Excel interpret everything as text use "mso-number-format:\"\\@\"".}
\item{total_columns}{The total number of columns including the rowlabel and the
specer cells}
\item{align.cgroup}{The justification of the \code{cgroups}}
\item{css.cgroup}{The same as \code{css.class} but for cgroup formatting.}
\item{top_row_style}{The top row has a special style depending on
the \code{ctable} option in the \code{htmlTable} call.}
\item{rnames}{Default rownames are generated from \code{\link[base]{rownames}(x)}. If you
provide \code{FALSE} then it will skip the rownames. \emph{Note:} For \code{data.frames}
if you do \code{\link[base]{rownames}(my_dataframe) <- NULL} it still has
rownames. Thus you need to use \code{FALSE} if you want to
surpress rownames for \code{data.frames}.}
\item{rowlabel}{If the table has rownames or \code{rnames},
rowlabel is a character string containing the
column heading for the \code{rnames}.}
\item{pos.rowlabel}{Where the rowlabel should be positioned. This value can be \code{"top"},
\code{"bottom"}, \code{"header"}, or a integer between \code{1} and \code{nrow(cgroup) + 1}. The options
\code{"bottom"} and \code{"header"} are the same, where the row label is presented at the same level as
the header.}
\item{cgroup_spacer_cells}{The spacer cells due to the multiple cgroup levels.
With multiple rows in cgroup we need to keep track of how many spacer cells
occur between the columns. This variable contains is of the size \code{ncol(x)-1}
and 0 if there is no cgroup element between.}
\item{css.cell}{The css.cell element allows you to add any possible CSS style to your
table cells. See section below for details.}
\item{align.header}{A character strings specifying alignment for column header,
defaulting to centered, i.e. \code{\link[base]{paste}(rep('c',ncol(x)),collapse='')}.}
}
\value{
\code{string} Returns the html string for the \code{...} element
}
\description{
Renders the table head (thead)
}
\keyword{internal}
htmlTable/man/txtMergeLines.Rd 0000644 0001762 0000144 00000002144 13572022513 016023 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/txtFrmt.R
\name{txtMergeLines}
\alias{txtMergeLines}
\title{A merges lines while preserving the line break for html/LaTeX}
\usage{
txtMergeLines(..., html = 5)
}
\arguments{
\item{...}{The lines that you want to be joined}
\item{html}{If HTML compatible output should be used. If \code{FALSE}
it outputs LaTeX formatting. Note if you set this to 5
then the html5 version of \emph{br} will be used: \code{
}
otherwise it uses the \code{
} that is compatible
with the xhtml-formatting.}
}
\value{
string
}
\description{
This function helps you to do a multiline
table header in both html and in LaTeX. In
html this isn't that tricky, you just use
the
command but in LaTeX I often find
myself writing vbox/hbox stuff and therefore
I've created this simple helper function
}
\examples{
txtMergeLines("hello", "world")
txtMergeLines("hello", "world", html=FALSE)
txtMergeLines("hello", "world", list("A list", "is OK"))
}
\seealso{
Other text formatters:
\code{\link{txtPval}()},
\code{\link{txtRound}()}
}
\concept{text formatters}
htmlTable/man/prPrepareCgroup.Rd 0000644 0001762 0000144 00000004046 13572022513 016354 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prPrepareCgroup}
\alias{prPrepareCgroup}
\title{Prepares the cgroup argument}
\usage{
prPrepareCgroup(x, cgroup, n.cgroup, align.cgroup, css.cgroup)
}
\arguments{
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
\item{cgroup}{A vector, matrix or list of character strings defining major column header. The default
is to have none. These elements are also known as \emph{column spanners}. If you want a column \emph{not}
to have a spanner then put that column as "". If you pass cgroup and \code{n.crgroup} as
matrices you can have column spanners for several rows. See cgroup section below for details.}
\item{n.cgroup}{An integer vector, matrix or list containing the number of columns for which each element in
cgroup is a heading. For example, specify \code{cgroup=c("Major_1","Major_2")},
\code{n.cgroup=c(3,3)} if \code{"Major_1"} is to span columns 1-3 and
\code{"Major_2"} is to span columns 4-6.
\code{rowlabel} does not count in the column numbers. You can omit \code{n.cgroup}
if all groups have the same number of columns. If the n.cgroup is one less than
the number of columns in the matrix/data.frame then it automatically adds those.}
\item{align.cgroup}{The justification of the \code{cgroups}}
\item{css.cgroup}{The same as \code{css.class} but for cgroup formatting.}
}
\value{
\code{list(cgroup, n.cgroup, align.cgroup, cgroup_spacer_cells)}
}
\description{
Due to the complicated structure of multilevel cgroups there
some preparation for the cgroup options is required.
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddCells}()},
\code{\link{prAddSemicolon2StrEnd}()},
\code{\link{prEscapeHtml}()},
\code{\link{prGetCgroupHeader}()},
\code{\link{prGetRowlabelPos}()},
\code{\link{prGetStyle}()},
\code{\link{prPrepareAlign}()},
\code{\link{prTblNo}()}
}
\concept{hidden helper functions for htmlTable}
\keyword{internal}
htmlTable/man/htmlTableWidget-shiny.Rd 0000644 0001762 0000144 00000002216 13407215301 017435 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTableWidget.R
\name{htmlTableWidget-shiny}
\alias{htmlTableWidget-shiny}
\alias{htmlTableWidgetOutput}
\alias{renderHtmlTableWidget}
\title{Shiny bindings for htmlTableWidget}
\usage{
htmlTableWidgetOutput(outputId, width = "100\%", height = "400px")
renderHtmlTableWidget(expr, env = parent.frame(), quoted = FALSE)
}
\arguments{
\item{outputId}{output variable to read from}
\item{width, height}{Must be a valid CSS unit (like \code{'100\%'},
\code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
string and have \code{'px'} appended.}
\item{expr}{An expression that generates a htmlTableWidget}
\item{env}{The environment in which to evaluate \code{expr}.}
\item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This
is useful if you want to save an expression in a variable.}
}
\description{
Output and render functions for using htmlTableWidget within Shiny
applications and interactive Rmd documents.
}
\examples{
\dontrun{
# In the UI:
htmlTableWidgetOutput("mywidget")
# In the server:
renderHtmlTableWidget({htmlTableWidget(iris)})
}
}
htmlTable/man/prEscapeHtml.Rd 0000644 0001762 0000144 00000001632 13572022513 015621 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prEscapeHtml}
\alias{prEscapeHtml}
\title{Remove html entities from table}
\usage{
prEscapeHtml(x)
}
\arguments{
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
}
\value{
\code{x} without the html entities
}
\description{
Removes the htmlEntities from table input data. Note that
this also replaces $ signs in order to remove the MathJax
issue.
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddCells}()},
\code{\link{prAddSemicolon2StrEnd}()},
\code{\link{prGetCgroupHeader}()},
\code{\link{prGetRowlabelPos}()},
\code{\link{prGetStyle}()},
\code{\link{prPrepareAlign}()},
\code{\link{prPrepareCgroup}()},
\code{\link{prTblNo}()}
}
\concept{hidden helper functions for htmlTable}
htmlTable/man/prTblNo.Rd 0000644 0001762 0000144 00000002023 13572022513 014605 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prTblNo}
\alias{prTblNo}
\title{Gets the table counter string}
\usage{
prTblNo(caption)
}
\arguments{
\item{The}{caption}
}
\value{
\code{string} Returns a string formatted according to
the table_counter_str and table_counter_roman. The number is
decided by the table_counter variable
}
\description{
Returns the string used for htmlTable to number the different tables.
Uses options \code{table_counter}, \code{table_counter_str},
and \code{table_counter_roman} to produce the final string. You
can set each option by simply calling \code{options()}.
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddCells}()},
\code{\link{prAddSemicolon2StrEnd}()},
\code{\link{prEscapeHtml}()},
\code{\link{prGetCgroupHeader}()},
\code{\link{prGetRowlabelPos}()},
\code{\link{prGetStyle}()},
\code{\link{prPrepareAlign}()},
\code{\link{prPrepareCgroup}()}
}
\concept{hidden helper functions for htmlTable}
\keyword{internal}
htmlTable/man/prPrepareColors.Rd 0000644 0001762 0000144 00000001054 13407215301 016346 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prPrepareColors}
\alias{prPrepareColors}
\title{Prepares the alternating colors}
\usage{
prPrepareColors(clr, n, ng, gtxt)
}
\arguments{
\item{clr}{The colors}
\item{n}{The number of rows/columns applicable to the color}
\item{ng}{The n.rgroup/n.cgroup argument if applicable}
\item{gtxt}{The rgroup/cgroup texts}
}
\value{
\code{character} A vector containing hexadecimal colors
}
\description{
Prepares the alternating colors
}
\keyword{internal}
htmlTable/man/prGetAlign.Rd 0000644 0001762 0000144 00000001452 13412664215 015272 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prGetAlign}
\alias{prGetAlign}
\title{Gets alignment}
\usage{
prGetAlign(align, index)
}
\arguments{
\item{align}{A character strings specifying column alignments, defaulting to
\code{\link[base]{paste}(rep('c',ncol(x)),collapse='')} to center. Valid alignments are
l = left, c = center and r = right. You can also specify \code{align='c|c'} and
other LaTeX tabular formatting. If you want to set the alignment of the
rownames this string needst to be \code{ncol(x) + 1}, otherwise it automatically
pads the string with a left alignment for the rownames.}
\item{index}{The index of the align parameter of interest}
}
\description{
Gets alignment
}
\concept{hidden helper functions for}
\keyword{internal}
htmlTable/man/tblNoLast.Rd 0000644 0001762 0000144 00000001261 13572022513 015132 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable.R
\name{tblNoLast}
\alias{tblNoLast}
\title{Gets the last table number}
\usage{
tblNoLast(roman = getOption("table_counter_roman", FALSE))
}
\arguments{
\item{roman}{Whether or not to use roman numbers instead
of arabic. Can also be set through \code{options(table_caption_no_roman = TRUE)}}
}
\description{
The function relies on \code{options("table_counter")}
in order to keep track of the last number.
}
\examples{
org_opts <- options(table_counter=1)
tblNoLast()
options(org_opts)
}
\seealso{
Other table functions:
\code{\link{htmlTable}},
\code{\link{tblNoNext}()}
}
\concept{table functions}
htmlTable/man/tblNoNext.Rd 0000644 0001762 0000144 00000001261 13572022513 015145 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable.R
\name{tblNoNext}
\alias{tblNoNext}
\title{Gets the next table number}
\usage{
tblNoNext(roman = getOption("table_counter_roman", FALSE))
}
\arguments{
\item{roman}{Whether or not to use roman numbers instead
of arabic. Can also be set through \code{options(table_caption_no_roman = TRUE)}}
}
\description{
The function relies on \code{options("table_counter")}
in order to keep track of the last number.
}
\examples{
org_opts <- options(table_counter=1)
tblNoNext()
options(org_opts)
}
\seealso{
Other table functions:
\code{\link{htmlTable}},
\code{\link{tblNoLast}()}
}
\concept{table functions}
htmlTable/man/prMergeClr.Rd 0000644 0001762 0000144 00000001173 13407215301 015270 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prMergeClr}
\alias{prMergeClr}
\title{Merges multiple colors}
\usage{
prMergeClr(clrs)
}
\arguments{
\item{clrs}{The colors}
}
\value{
\code{character} A hexadecimal color
}
\description{
Uses the \code{\link[grDevices]{colorRampPalette}} for merging colors.
\emph{Note:} When merging more than 2 colors the order in the color
presentation matters. Each color is merged with its neigbors before
merging with next. If there is an uneven number of colors the middle
color is mixed with both left and right side.
}
\keyword{internal}
htmlTable/man/prGetCgroupHeader.Rd 0000644 0001762 0000144 00000005511 13572022513 016604 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prGetCgroupHeader}
\alias{prGetCgroupHeader}
\title{Retrieve a header row}
\usage{
prGetCgroupHeader(
x,
cgroup_vec,
n.cgroup_vec,
cgroup_vec.just,
css.cgroup_vec,
row_no,
top_row_style,
rnames,
rowlabel,
pos.rowlabel,
cgroup_spacer_cells,
css.cell
)
}
\arguments{
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
\item{cgroup_vec}{The cgroup may be a matrix, this is
just one row of that matrix}
\item{n.cgroup_vec}{The same as above but for the counter}
\item{cgroup_vec.just}{The same as above bot for the justificaiton}
\item{css.cgroup_vec}{The CSS row corresponding to the current row}
\item{row_no}{The row number within the header group. Useful for multirow
headers when we need to output the rowlabel at the \code{pos.rowlabel}
level.}
\item{top_row_style}{The top row has a special style depending on
the \code{ctable} option in the \code{htmlTable} call.}
\item{rnames}{Default rownames are generated from \code{\link[base]{rownames}(x)}. If you
provide \code{FALSE} then it will skip the rownames. \emph{Note:} For \code{data.frames}
if you do \code{\link[base]{rownames}(my_dataframe) <- NULL} it still has
rownames. Thus you need to use \code{FALSE} if you want to
surpress rownames for \code{data.frames}.}
\item{rowlabel}{If the table has rownames or \code{rnames},
rowlabel is a character string containing the
column heading for the \code{rnames}.}
\item{pos.rowlabel}{Where the rowlabel should be positioned. This value can be \code{"top"},
\code{"bottom"}, \code{"header"}, or a integer between \code{1} and \code{nrow(cgroup) + 1}. The options
\code{"bottom"} and \code{"header"} are the same, where the row label is presented at the same level as
the header.}
\item{cgroup_spacer_cells}{The spacer cells due to the multiple cgroup levels.
With multiple rows in cgroup we need to keep track of how many spacer cells
occur between the columns. This variable contains is of the size \code{ncol(x)-1}
and 0 if there is no cgroup element between.}
\item{css.cell}{The css.cell element allows you to add any possible CSS style to your
table cells. See section below for details.}
}
\value{
\code{string}
}
\description{
This function retrieves a header row, i.e. a row
within the elements on top of the table. Used by
\code{\link{htmlTable}}.
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddCells}()},
\code{\link{prAddSemicolon2StrEnd}()},
\code{\link{prEscapeHtml}()},
\code{\link{prGetRowlabelPos}()},
\code{\link{prGetStyle}()},
\code{\link{prPrepareAlign}()},
\code{\link{prPrepareCgroup}()},
\code{\link{prTblNo}()}
}
\concept{hidden helper functions for htmlTable}
\keyword{internal}
htmlTable/man/prAddSemicolon2StrEnd.Rd 0000644 0001762 0000144 00000001523 13572022513 017336 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prAddSemicolon2StrEnd}
\alias{prAddSemicolon2StrEnd}
\title{Add a ; at the end}
\usage{
prAddSemicolon2StrEnd(my_str)
}
\arguments{
\item{my_str}{The string that is to be processed}
}
\value{
\code{string}
}
\description{
The CSS expects a semicolon at the end of each argument
this function just adds a semicolong if none is given
and remove multiple semicolon if such exist
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddCells}()},
\code{\link{prEscapeHtml}()},
\code{\link{prGetCgroupHeader}()},
\code{\link{prGetRowlabelPos}()},
\code{\link{prGetStyle}()},
\code{\link{prPrepareAlign}()},
\code{\link{prPrepareCgroup}()},
\code{\link{prTblNo}()}
}
\concept{hidden helper functions for htmlTable}
\keyword{internal}
htmlTable/man/htmlTableWidget.Rd 0000644 0001762 0000144 00000002425 13572022513 016313 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTableWidget.R
\name{htmlTableWidget}
\alias{htmlTableWidget}
\title{htmlTable with pagination widget}
\usage{
htmlTableWidget(
x,
number_of_entries = c(10, 25, 100),
width = NULL,
height = NULL,
elementId = NULL,
...
)
}
\arguments{
\item{x}{A data frame to be rendered}
\item{number_of_entries}{a numeric vector with the number of entries per page to show.
If there is more than one number given, the user will be able to show the number
of rows per page in the table.}
\item{width}{Fixed width for widget (in css units). The default is
\code{NULL}, which results in intelligent automatic sizing based on the
widget's container.}
\item{height}{Fixed height for widget (in css units). The default is
\code{NULL}, which results in intelligent automatic sizing based on the
widget's container.}
\item{elementId}{Use an explicit element ID for the widget (rather than an
automatically generated one). Useful if you have other JavaScript that
needs to explicitly discover and interact with a specific widget instance.}
\item{...}{Additional parameters passed to htmlTable}
}
\value{
an htmlwidget showing the paginated table
}
\description{
This widget renders a table with pagination into an htmlwidget
}
htmlTable/man/prIsNotebook.Rd 0000644 0001762 0000144 00000000631 13407215301 015642 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable.R
\name{prIsNotebook}
\alias{prIsNotebook}
\title{Detects if the call is made from within an RStudio Rmd file or a file
with the html_notebook output set.}
\usage{
prIsNotebook()
}
\description{
Detects if the call is made from within an RStudio Rmd file or a file
with the html_notebook output set.
}
\keyword{internal}
htmlTable/man/prPrepareAlign.Rd 0000644 0001762 0000144 00000003660 13572022513 016150 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/htmlTable_helpers.R
\name{prPrepareAlign}
\alias{prPrepareAlign}
\title{Prepares the align to match the columns}
\usage{
prPrepareAlign(align, x, rnames, default_rn = "l")
}
\arguments{
\item{align}{A character strings specifying column alignments, defaulting to
\code{\link[base]{paste}(rep('c',ncol(x)),collapse='')} to center. Valid alignments are
l = left, c = center and r = right. You can also specify \code{align='c|c'} and
other LaTeX tabular formatting. If you want to set the alignment of the
rownames this string needst to be \code{ncol(x) + 1}, otherwise it automatically
pads the string with a left alignment for the rownames.}
\item{x}{The matrix/data.frame with the data. For the \code{print} and \code{knit_print}
it takes a string of the class \code{htmlTable} as \code{x} argument.}
\item{rnames}{Default rownames are generated from \code{\link[base]{rownames}(x)}. If you
provide \code{FALSE} then it will skip the rownames. \emph{Note:} For \code{data.frames}
if you do \code{\link[base]{rownames}(my_dataframe) <- NULL} it still has
rownames. Thus you need to use \code{FALSE} if you want to
surpress rownames for \code{data.frames}.}
\item{default_rn}{The default rowname alignment. This is an option
as the header uses the same function and there may be differences in
how the alignments should be implemented.}
}
\description{
The alignment may be tricky and this function therefore simplifies
this process by extending/shortening the alignment to match the
correct number of columns.
}
\seealso{
Other hidden helper functions for htmlTable:
\code{\link{prAddCells}()},
\code{\link{prAddSemicolon2StrEnd}()},
\code{\link{prEscapeHtml}()},
\code{\link{prGetCgroupHeader}()},
\code{\link{prGetRowlabelPos}()},
\code{\link{prGetStyle}()},
\code{\link{prPrepareCgroup}()},
\code{\link{prTblNo}()}
}
\concept{hidden helper functions for htmlTable}
\keyword{internal}
htmlTable/DESCRIPTION 0000644 0001762 0000144 00000002575 13572030437 013711 0 ustar ligges users Package: htmlTable
Version: 1.13.3
Date: 2019-12-04
Title: Advanced Tables for Markdown/HTML
Authors@R: c(
person("Max", "Gordon", email = "max@gforge.se",
role = c("aut", "cre")),
person("Stephen", "Gragg", role=c("aut")),
person("Peter", "Konings", role=c("aut")))
Maintainer: Max Gordon
Description: Tables with state-of-the-art layout elements such as row spanners,
column spanners, table spanners, zebra striping, and more. While allowing
advanced layout, the underlying css-structure is simple in order to maximize
compatibility with word processors such as 'MS Word' or 'LibreOffice'. The package
also contains a few text formatting functions that help outputting text
compatible with HTML/LaTeX.
License: GPL (>= 3)
URL: http://gforge.se/packages/
BugReports: https://github.com/gforge/htmlTable/issues
Biarch: yes
Imports: stringr, knitr (>= 1.6), magrittr (>= 1.5), methods,
checkmate, htmlwidgets, htmltools, rstudioapi (>= 0.6)
Suggests: testthat, XML, xtable, ztable, Hmisc, reshape, rmarkdown,
pander, chron, lubridate, tibble, tidyr (>= 0.7.2), dplyr (>=
0.7.4)
Encoding: UTF-8
NeedsCompilation: no
VignetteBuilder: knitr
RoxygenNote: 7.0.2
Packaged: 2019-12-04 21:50:14 UTC; max
Author: Max Gordon [aut, cre],
Stephen Gragg [aut],
Peter Konings [aut]
Repository: CRAN
Date/Publication: 2019-12-04 22:20:15 UTC
htmlTable/build/ 0000755 0001762 0000144 00000000000 13572025026 013267 5 ustar ligges users htmlTable/build/vignette.rds 0000644 0001762 0000144 00000000434 13572025026 015627 0 ustar ligges users RN0tM Q>wD*qAlZKlC?aڡzzgƻ;kB(+ffs|Wpmd,y1ז6b^ܮT{o0=ݟبaOf||chhy:]#&v+qrx O_wCyBSo?b|ɇ@X4 $
7{`ViR.ܯﱣWALpȊK7
~~C\ htmlTable/tests/ 0000755 0001762 0000144 00000000000 13407215301 013324 5 ustar ligges users htmlTable/tests/testthat/ 0000755 0001762 0000144 00000000000 13572030437 015174 5 ustar ligges users htmlTable/tests/testthat/test-htmlTable_total.R 0000644 0001762 0000144 00000005707 13407215301 021414 0 ustar ligges users library(testthat)
context("htmlTable - the total argument")
test_that("Throws errors",{
mx <- matrix(1, ncol=3, nrow=6)
expect_error(htmlTable(mx, total = c(TRUE, TRUE)))
expect_error(htmlTable(mx, total = c(TRUE, TRUE),
tspanner = letters[1:3], n.tspanner = rep(2, times = 3)))
expect_error(htmlTable(mx, total = -1))
expect_error(htmlTable(mx, total = nrow(mx) + 1))
expect_error(htmlTable(mx, total = "asdasd"))
})
test_that("Correct rows",{
mx <- matrix(1:6, ncol=3, nrow=6)
table_str <- htmlTable(mx,
css.total = "color: red",
total=TRUE)
expect_match(table_str, "]*>[^>]+color: red[^>]+>6")
table_str <- htmlTable(mx,
css.total = "color: red",
total=4)
expect_match(table_str, " ]*>[^>]+color: red[^>]+>4")
table_str <- htmlTable(mx,
css.total = "color: red",
total=c(4, 2))
expect_false(grepl(" ]*>[^>]+color: red[^>]+>[1356789]+", table_str))
expect_match(table_str, " ]*>[^>]+color: red[^>]+>2")
expect_match(table_str, " ]*>[^>]+color: red[^>]+>4")
table_str <- htmlTable(mx,
css.total = "color: red",
total=c(4, 2))
expect_false(grepl(" ]*>[^>]+color: red[^>]+>[1356789]+", table_str))
expect_match(table_str, " ]*>[^>]+color: red[^>]+>2")
expect_match(table_str, " ]*>[^>]+color: red[^>]+>4")
})
test_that("Check tspanner", {
mx <- matrix(1:6, ncol=3, nrow=6)
table_str <- htmlTable(mx, tspanner = letters[1:2], n.tspanner = c(3, 3),
css.total = "color: red",
total="tspanner")
expect_false(grepl(" ]*>[^>]+color: red[^>]+>[1245789]+", table_str))
expect_match(table_str, " ]*>[^>]+color: red[^>]+>3")
expect_match(table_str, " ]*>[^>]+color: red[^>]+>6")
})
test_that("Check choosing css.style", {
mx <- matrix(1:6, ncol=3, nrow=6)
table_str <- htmlTable(mx, tspanner = letters[1:2], n.tspanner = c(3, 3),
css.total = c("color: red", "color: green"),
total="tspanner")
expect_false(grepl(" ]*>[^>]+color: red[^>]+>[1245789]+", table_str))
expect_match(table_str, " ]*>[^>]+color: red[^>]+>3")
expect_match(table_str, " ]*>[^>]+color: green[^>]+>6")
})
test_that("The total should be added to the output if used with addmargins", {
var1 <- LETTERS[1:3]
var2 <- LETTERS[c(4:5, 5)]
total_out <-
table(var1, var2) %>%
addmargins %>%
htmlTable(css.total = "background: purple")
expect_match(total_out, "]+background: purple[^>]+>[^>]*Sum | ",
info = "Expect the variable name to appear as a cgroup")
expect_match(total_out, "]*>var2",
info = "Expect the variable name to appear as a cgroup")
})
htmlTable/tests/testthat/test-txtFrmt.R 0000644 0001762 0000144 00000016063 13412664215 017752 0 ustar ligges users library('testthat')
context('txtInt')
test_that("Add zero", {
expect_equal(txtInt(5), "5")
expect_equal(txtInt(106), "106")
expect_equal(txtInt(1006), "1,006")
expect_equal(txtInt(c(5, 106, 10006)),
c("5", "106", "10,006"))
expect_equal(txtInt(1000, language = "se", html = TRUE), "1000")
expect_equal(txtInt(10000, language = "se", html = TRUE), "10 000")
expect_equal(txtInt(10000, language = "se", html = FALSE), "10 000")
mtrx <- matrix(seq(from = 10,
to = 10000,
length.out = 3*6),
ncol = 3, nrow = 6)
mtrx <- round(mtrx)
int_mtrx <- txtInt(mtrx)
expect_equal(dim(mtrx),
dim(int_mtrx))
expect_equal(int_mtrx[3,1],
txtInt(mtrx[3,1]))
})
test_that("Throw nsmall warning", {
expect_warning(txtInt(.5), regexp = "The function can only be served integers")
expect_silent(txtInt(.5, nsmall=1))
expect_warning(txtInt(c(.5, .5)), regexp = "The function can only be served integers")
expect_silent(txtInt(c(.5, .5), nsmall=2))
})
context('txtPval')
test_that("Add zero", {
expect_equal(txtPval(.5, lim.2dec=10^-1), "0.50")
expect_equal(txtPval(.06, lim.2dec=10^-1), "0.06")
expect_equal(txtPval(.06, lim.2dec=10^-2), "0.060")
expect_equal(txtPval(.06451, lim.2dec=10^-3), "0.065")
expect_equal(txtPval(.00006451, lim.sig=10^-3), "< 0.001")
expect_warning(txtPval("a", lim.sig = 10^-3))
})
context('txtRound')
test_that("Numerical matrices",{
test_mx <- matrix(c(1, 1.11, 1.25,
2.50, 2.55, 2.45,
3.2313, 3, pi),
ncol = 3, byrow=TRUE)
expect_equivalent(txtRound(test_mx, 1),
t(apply(test_mx, 1, function(x) sprintf("%.1f", x))))
expect_equivalent(txtRound(test_mx, 1, excl.cols = 2)[2,2],
as.character(test_mx[2,2]))
expect_equivalent(txtRound(test_mx, 1, excl.rows = 2)[2,2],
as.character(test_mx[2,2]))
expect_equivalent(txtRound(test_mx, 1, excl.cols = 2)[2,1],
sprintf("%.1f", test_mx[2,1]))
expect_equivalent(txtRound(test_mx, 1, excl.rows = 2)[1,1],
sprintf("%.1f", test_mx[1,1]))
expect_equivalent(txtRound(test_mx, 1, excl.cols = 2)[2,3],
sprintf("%.1f", test_mx[2,3]))
rownames(test_mx) <- letters[1:nrow(test_mx)]
colnames(test_mx) <- LETTERS[1:ncol(test_mx)]
expect_equivalent(txtRound(test_mx, 1, excl.cols = "A")[3,"A"],
as.character(test_mx[3,"A"]))
expect_equivalent(txtRound(test_mx, 1, excl.cols = "A")[3,"C"],
sprintf("%.1f", test_mx[3,"C"]))
expect_equivalent(txtRound(test_mx, 1, excl.rows = "a")["a", 3],
as.character(test_mx["a", 3]))
expect_equivalent(txtRound(test_mx, 1, excl.rows = "a")["c", 3],
sprintf("%.1f", test_mx["c", 3]))
expect_equivalent(txtRound(matrix(c(NA, 2.22), ncol=1), 1)[1,1],
"")
expect_equivalent(txtRound(matrix(c(NA, 2.22), ncol=1), 1, txt.NA = "missing")[1,1],
"missing")
expect_error(txtRound(test_mx, digits = c(2, 3, 4, 5)))
expect_error(txtRound(test_mx, digits = c(2, 3)))
})
test_that("Character matrices",{
test_mx <- matrix(c(1, 1.11, 1.25,
2.50, 2.55, 2.45,
3.2313, 3, pi),
ncol = 3, byrow=TRUE)
ch_test_mx <- cbind(test_mx, "a")
expect_equivalent(txtRound(ch_test_mx, 1)[,1:ncol(test_mx)],
t(apply(test_mx, 1, function(x) sprintf("%.1f", x))))
expect_equivalent(txtRound(test_mx, 1, excl.cols = 2)[2,2],
as.character(test_mx[2,2]))
expect_equivalent(txtRound(test_mx, 1, excl.rows = 2)[2,2],
as.character(test_mx[2,2]))
expect_equivalent(txtRound(test_mx, 1, excl.cols = 2)[2,1],
sprintf("%.1f", test_mx[2,1]))
expect_equivalent(txtRound(test_mx, 1, excl.rows = 2)[1,1],
sprintf("%.1f", test_mx[1,1]))
})
test_that("Supplying a data.frame",{
test_df <- matrix(c(1, 1.11, 1.25,
2.50, 2.55, 2.45,
3.2313, 3, pi),
ncol = 3, byrow=TRUE) %>%
as.data.frame()
test_df$text = LETTERS[1:nrow(test_df)]
expect_equal(dim(txtRound(test_df, 1)),
dim(test_df))
expect_equivalent(as.matrix(txtRound(test_df, 1)[,1:3]),
t(apply(test_df[,1:3], 1, function(x) sprintf("%.1f", x))))
expect_equal(txtRound(test_df, 1)$text,
test_df$text)
})
test_that("Supplying a table",{
out <- txtRound(table(1:4, 4:1))
expect_equal(nrow(out), 4)
expect_equal(ncol(out), 4)
})
test_that("Supplying a vector for the digits",{
w <- matrix((1:8)/7, ncol=4)
w_out <- txtRound(w, digits=1:4)
for (digits in 1:4)
expect_equivalent(w_out[,digits],
sprintf(paste0("%.", digits, "f"), w[,digits]),
paste("Expected the number of digits to be", digits))
})
test_that("The txtRound should accept without warning a vector",{
w <- c(.1, .2, .7)
expect_silent(w_out <- txtRound(w))
expect_equivalent(w_out, c("0", "0", "1"))
w_out <- txtRound(w, digits = 0:2)
expect_equivalent(w_out, c("0", "0.2", "0.70"))
expect_error(txtRound(w, digits = 0:20))
})
test_that("Numbers that round to 0 should not have -, i.e. no -0.0",{
expect_equal(txtRound(matrix(-.01), digits = 1),
matrix("0.0"))
expect_equal(txtRound(matrix("-.01"), digits = 0),
matrix("0"))
})
test_that("Character vectors work", {
test_str <- c("AA 2 2A", "-1.2 aaa",
"-1", "2.8888")
correct_str <- c("2.0", "-1.2", "-1.0", "2.9")
for (i in 1:length(test_str))
expect_equivalent(txtRound(test_str[i], digits = 1),
correct_str[i], info = paste("Test case", i))
})
test_that("Keep minimila digits", {
expect_equal(txtRound(c(0.1, 0.01, 0.001), digits = 2), c("0.10", "0.01","0.00"))
expect_equal(txtRound(c(0.1, 0.01,
0.0018,
0.0012,
0.00012),
digits = 2,
digits.nonzero = 3),
c("0.10", "0.01","0.002","0.001","0.00"))
expect_equal(txtRound(c(10.1, 0.1, 0.0012, 0.0012),
digits = c(0, 2, 2, 2),
digits.nonzero = c(1,2,2,3)),
c("10", "0.10", "0.00", "0.001"))
})
test_that("Peter's issues raised in #34", {
expect_silent(txtRound(c(1, 2, 3, 4)))
expect_silent(txtRound(c(1, 2, 3, NA)))
expect_silent(txtRound(c(NA, NA, NA, NA)))
})
test_that("Scientific notation",{
expect_equal(txtRound("1.1234", 1), "1.1")
expect_equal(txtRound("1.1234e1", 1), "1.12e+01")
expect_equal(txtRound("1.1234e+01", 1), "1.12e+01")
expect_equal(txtRound("1.1234321e2", 2), "1.1234e+02")
# Doesn't work due to depares(substitute()) limitations
# expect_equal(txtRound(1.1234321e2, 2), "1.1234e+02")
expect_equal(txtRound(1.1234321e2, 2, scientific = TRUE), "1.1234e+02")
expect_equal(txtRound("1.1234321e2", 2, scientific = FALSE), "112.34")
})
htmlTable/tests/testthat/test-interactiveTable.R 0000644 0001762 0000144 00000030022 13407215301 021546 0 ustar ligges users library('testthat')
library('XML')
context('interactiveTable')
# A simple example
test_that("With empty rownames(mx) it should skip those",
{
mx <- matrix(1:6, ncol=3)
table_str <- interactiveTable(mx)
expect_false(grepl(" | ", table_str))
expect_false(grepl(" [^>]+>NA", table_str))
colnames(mx) <- sprintf("Col %s", LETTERS[1:NCOL(mx)])
table_str <- interactiveTable(mx)
expect_true(grepl("", table_str))
expect_false(grepl(" [^>]+>NA", table_str))
})
test_that("Empty cell names should be replaced with ''",
{
mx <- matrix(1:6, ncol=3)
mx[1,1] <- NA
table_str <- interactiveTable(mx)
expect_false(grepl(" [^>]+>NA", table_str))
})
test_that("The variable name should not be in the tables first row if no rownames(mx)",
{
mx <- matrix(1:6, ncol=3)
colnames(mx) <- sprintf("Col %s", LETTERS[1:NCOL(mx)])
table_str <- interactiveTable(mx)
expect_false(grepl("[^<]*[^>]+>mx", table_str))
})
test_that("A rowlabel without rownames indicates some kind of error and should throw an error",
{
mx <- matrix(1:6, ncol=3)
colnames(mx) <- sprintf("Col %s", LETTERS[1:NCOL(mx)])
expect_error(interactiveTable(mx, rowlabel="not_mx"))
})
# Add rownames
test_that("The rowname should appear",
{
mx <- matrix(1:6, ncol=3)
colnames(mx) <- sprintf("Col %s", LETTERS[1:NCOL(mx)])
rownames(mx) <- LETTERS[1:NROW(mx)]
table_str <- interactiveTable(mx)
class(table_str) <- "character"
parsed_table <- readHTMLTable(table_str)[[1]]
expect_equal(ncol(parsed_table), ncol(mx) + 1)
expect_match(table_str, " ]*>[^>]+>A")
expect_match(table_str, " ]*>[^>]+>B")
})
test_that("Check that basic output are the same as the provided matrix",
{
mx <- matrix(1:6, ncol=3)
colnames(mx) <- sprintf("Col %s", LETTERS[1:NCOL(mx)])
table_str <- interactiveTable(mx)
class(table_str) <- "character"
parsed_table <- readHTMLTable(table_str)[[1]]
expect_equal(ncol(parsed_table), ncol(mx), info="Cols did not match")
expect_equal(nrow(parsed_table), nrow(mx), info="Rows did not match")
expect_true(all(mx == parsed_table),
info="Some cells don't match the inputted cells")
})
test_that("rnames = FALSE it should skip those",
{
mx <- matrix(1:6, ncol=3)
rownames(mx) <- c("Row A", "Row B")
table_str <- interactiveTable(mx, rnames = FALSE)
expect_false(grepl("FALSE", table_str))
expect_false(grepl("Row A", table_str))
})
test_that("Test style formatter", {
styles <- c(background = "black", border ="1px solid grey")
expect_equivalent(length(prGetStyle(styles)), 1)
expect_match(prGetStyle(styles), "background: black;")
expect_match(prGetStyle(styles), "border: [^;]+grey;")
expect_match(prGetStyle(styles), "border: [^;]+grey;")
expect_match(prGetStyle(styles, a=2), "border: [^;]+grey;")
expect_error(prGetStyle(styles, "invalid style"))
expect_error(prGetStyle(styles, "invalid style:"))
expect_error(prGetStyle(styles, ":invalid style"))
expect_match(prGetStyle(styles, "valid: style"), "valid: style;")
expect_match(prGetStyle(styles, c(valid= "style")), "valid: style;")
expect_match(prGetStyle(styles, c(valid= "style", valid1= "style")), "valid: style; valid1: style;")
expect_match(prGetStyle(styles, c(valid= "style1", valid= "style2")), "valid: style2;")
expect_match(prGetStyle(styles, c(valid= "style1", valid= "style2"), "valid: style3"), "valid: style3;")
})
test_that("Test align functions", {
expect_equivalent(nchar(prPrepareAlign("lr", x = matrix(1, ncol=10))),
10)
expect_equivalent(nchar(prPrepareAlign("lr", x = matrix(1, ncol=2))),
2)
expect_equivalent(nchar(prPrepareAlign("lr", x = matrix(1, ncol=2), rnames = TRUE)),
3)
expect_equivalent(nchar(prPrepareAlign("l", x = matrix(1, ncol=2), rnames = TRUE)),
3)
expect_equivalent(nchar(prPrepareAlign("", x = matrix(1, ncol=2, nrow=2), rnames = TRUE)),
3)
expect_equivalent(attr(prPrepareAlign("r|rlt|r|", x = matrix(1, ncol=2, nrow=2), rnames = TRUE), "n"),
3)
expect_equivalent(attr(prPrepareAlign("r|rcl|lt|r|", x = matrix(1, ncol=5, nrow=2), rnames = TRUE), "n"),
6)
expect_match(prPrepareAlign("r|rcl|lt|r|", x = matrix(1, ncol=5, nrow=2), rnames = TRUE),
"^r")
expect_match(prPrepareAlign("l|r|", x = matrix(1, ncol=3, nrow=2), rnames = TRUE),
"^l|r|r|$")
align_str <- prPrepareAlign("r|rcl|lt|r|", x = matrix(1, ncol=5, nrow=2), rnames = TRUE)
expect_true("right" %in% prGetAlign(align_str, 1))
expect_true("right" %in% prGetAlign(align_str, 2))
expect_true("center" %in% prGetAlign(align_str, 3))
expect_true("left" %in% prGetAlign(align_str, 4))
expect_true("left" %in% prGetAlign(align_str, 5))
expect_true("right" %in% prGetAlign(align_str, 6))
expect_true("border-right" %in% names(prGetAlign(align_str, 1)))
expect_true("border-right" %in% names(prGetAlign(align_str, 4)))
expect_true("border-right" %in% names(prGetAlign(align_str, 5)))
expect_true("border-right" %in% names(prGetAlign(align_str, 6)))
expect_equivalent(length(prGetAlign(align_str, 1)), 2)
expect_equivalent(length(prGetAlign(align_str, 2)), 1)
expect_equivalent(length(prGetAlign(align_str, 6)), 2)
align_str <- prPrepareAlign("|c|rc", x = matrix(1, ncol=2, nrow=2), rnames = TRUE)
expect_true("border-right" %in% names(prGetAlign(align_str, 1)))
expect_true("border-left" %in% names(prGetAlign(align_str, 1)))
expect_true("center" %in% prGetAlign(align_str, 1))
mx <- matrix(1:6, ncol=3)
rownames(mx) <- c("Row A", "Row B")
table_str <- interactiveTable(mx, rname = FALSE)
expect_match(table_str, "text-align: center;[^>]*>1")
expect_match(table_str, "text-align: center;[^>]*>3")
expect_match(table_str, "text-align: center;[^>]*>5")
table_str <- interactiveTable(mx)
expect_match(table_str, "text-align: left;[^>]*>Row A")
expect_match(table_str, "text-align: center;[^>]*>1")
expect_match(table_str, "text-align: center;[^>]*>3")
expect_match(table_str, "text-align: center;[^>]*>5")
table_str <- interactiveTable(mx, align="r")
expect_match(table_str, "text-align: left;[^>]*>Ro")
expect_match(table_str, "text-align: right;[^>]*>1")
expect_match(table_str, "text-align: right;[^>]*>3")
expect_match(table_str, "text-align: right;[^>]*>5")
table_str <- interactiveTable(mx, align="|ll|r|r|")
expect_match(table_str, "text-align: left;[^>]*>Ro")
expect_match(table_str, "text-align: left;[^>]*>1")
expect_match(table_str, "text-align: right;[^>]*>3")
expect_match(table_str, "text-align: right;[^>]*>5")
expect_match(table_str, "border-left:[^>]*>Ro")
expect_match(table_str, "border-right:[^>]*>1")
expect_match(table_str, "border-right:[^>]*>3")
expect_match(table_str, "border-right:[^>]*>5")
})
test_that("Check color function",{
expect_equivalent(prPrepareColors(c("white", "#444444"), 2),
c("#ffffff", "#444444"))
expect_equivalent(prPrepareColors(c("white", "#444444"), 3),
c("#ffffff", "#444444", "#ffffff"))
expect_equivalent(prPrepareColors(c("white", "#444"), 3),
c("#ffffff", "#444444", "#ffffff"))
expect_null(attr(prPrepareColors(c("white", "#444444"), 3), "groups"))
expect_equivalent(attr(prPrepareColors(c("white", "#444444"),
n = 3,
ng = c(2, 3, 1),
gtxt = c("a", "b", "c")), "groups")[[1]],
c("#ffffff", "#ffffff"))
expect_equivalent(attr(prPrepareColors(c("white", "#444444"),
n = 3,
ng = c(2, 3, 1),
gtxt = c("a", "b", "c")), "groups")[[2]],
c("#444444", "#444444", "#444444"))
expect_equivalent(attr(prPrepareColors(c("white", "#444444"),
n = 3,
ng = c(2, 3, 1),
gtxt = c("a", "b", "c")), "groups")[[3]],
c("#ffffff"))
expect_equivalent(attr(prPrepareColors(c("white", "#444444", "none"),
n = 3,
ng = c(2, 3, 1),
gtxt = c("a", "b", "c")), "groups")[[3]],
c("none"))
expect_equivalent(attr(prPrepareColors(c("white", "none"),
n = 3,
ng = c(2, 3, 1),
gtxt = c("a", "b", "c")), "groups")[[2]],
c("none", "none", "none"))
## Test the merge colors
expect_equal(prMergeClr(c("white", "#444444")),
colorRampPalette(c("#FFFFFF", "#444444"))(3)[2])
expect_equal(prMergeClr(c("red", "#444444")),
colorRampPalette(c("red", "#444444"))(3)[2])
expect_equal(prMergeClr(c("#444444", "red")),
colorRampPalette(c("red", "#444444"))(3)[2])
expect_equal(prMergeClr(c("#FFFFFF", "#FFFFFF", "#FFFFFF")),
"#FFFFFF")
expect_equal(prMergeClr(c("#FFFFFF", "#FFFFFF", "#000000", "#000000")),
prMergeClr(c("#FFFFFF", "#000000")))
expect_equal(prMergeClr(c("#000000", "#FFFFFF", "#FFFFFF")),
prMergeClr(c("#FFFFFF", "#FFFFFF", "#000000")))
expect_equal(prMergeClr(c("#000000", "#FFFFFF", "#000000")),
prMergeClr(c("#FFFFFF", "#000000", "#FFFFFF")))
})
test_that("Test cell styles",{
mx <- matrix(1:3, nrow=2, ncol=3, byrow = TRUE)
mx_head <- LETTERS[1:ncol(mx)]
mx_rnames <- LETTERS[1:nrow(mx)]
expect_equal(dim(prPrepareCss(mx, "")),
dim(mx))
expect_equal(dim(prPrepareCss(mx, "", header = mx_head, rnames = mx_rnames)),
dim(mx))
expect_equal(dim(prPrepareCss(mx, "", header = mx_head, rnames = mx_rnames)),
dim(mx))
expect_equal(dim(prPrepareCss(mx, rep("", times=ncol(mx)))),
dim(mx))
expect_error(prPrepareCss(mx, rep("", times=nrow(mx))))
mx_cell.style <- matrix(c("a", "b", "c", "d"), nrow=2, ncol=4, byrow = TRUE)
expect_equal(prPrepareCss(mx, mx_cell.style, rnames = mx_rnames)[2,1],
"b")
expect_error(prPrepareCss(mx, mx_cell.style))
mx_cell.style <- matrix(c("a", "b", "c", "d"), nrow=3, ncol=4, byrow = TRUE)
expect_equal(prPrepareCss(mx, mx_cell.style,
header = mx_head,
rnames = mx_rnames)[2,1],
"b")
expect_error(prPrepareCss(mx, mx_cell.style, rnames = mx_rnames))
})
test_that("Test prAddSemicolon2StrEnd",{
test_str <- "background: white"
expect_equal(prAddSemicolon2StrEnd(test_str),
paste0(test_str, ";"))
test_str <- c("", "", `background-color` = "none")
expect_equivalent(prAddSemicolon2StrEnd(test_str),
paste0(test_str[3], ";"))
expect_equal(names(prAddSemicolon2StrEnd(test_str)),
names(test_str[3]))
})
test_that("Problem with naming in stringr 1.0.0", {
style_bug <- structure(c("", "font-weight: 900;", "#f7f7f7"),
.Names = c("", "", "background-color"))
expect_false(is.null(names(prAddSemicolon2StrEnd(style_bug))))
expect_match(prGetStyle(style_bug),
regexp = "^font-weight: 900; background-color: #f7f7f7")
})
test_that("Handling data.frames with factors",{
tmp <- data.frame(a = 1:3,
b = factor(x = 1:3,
labels = c("Unique_Factor_1",
"Factor_2",
"Factor_3")))
str <- interactiveTable(tmp)
expect_true(grepl("Unique_Factor_1", str))
tmp <- data.frame(a = 1,
b = factor(x = 1,
labels = c("1.2")))
expect_true(txtRound(tmp)$b == 1)
})
test_that("Check Javascript string",{
js <- prGetScriptString(structure(1:3, javascript= c("a", "B")))
expect_gt(length(strsplit(js, " |