Skip to content

Commit

Permalink
Address comments from CRAN reviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminrich committed May 6, 2021
1 parent ec5cd03 commit 9a99dc8
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 31 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: ttt
Type: Package
Version: 1.0
Date: 2021-05-04
Date: 2021-05-06
Title: The Table Tool
Authors@R: person("Benjamin", "Rich", role=c("aut", "cre"), email="mail@benjaminrich.net")
URL: https://github.com/benjaminrich/ttt
BugReports: https://github.com/benjaminrich/ttt/issues
Description: The Table Tool (a.k.a. "Tables! Tables! Tables!") creates formatted
HTML tables of in a flexible and convenient way.
Description: Create structured, formatted HTML tables of in a flexible and
convenient way.
License: GPL-3
Imports: stats,Formula,knitr,htmltools
Suggests: rmarkdown,table1,magrittr
Expand Down
36 changes: 19 additions & 17 deletions R/ttt.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ ttt <- function(x, ...) {
#' @importFrom Formula Formula model.part
ttt.data.frame <- function(x, formula, ..., render, lab, caption, footnote,
expand.along=c("rows", "columns"), drop=c("both", "rows", "columns", "none"),
collapse.cells=TRUE, topclass=NULL, id=NULL, css=NULL, row.names=T) {
collapse.cells=TRUE, topclass=NULL, id=NULL, css=NULL, row.names=TRUE) {

if (missing(formula)) {
value <- unlist(as.list(format(x)))
eg <- expand.grid(rownames(x), colnames(x))
rowvars <- eg[, 1, drop=F]
colvars <- eg[, 2, drop=F]
rowvars <- eg[, 1, drop=FALSE]
colvars <- eg[, 2, drop=FALSE]
if (missing(lab) || is.null(lab)) {
names(rowvars) <- " " # Avoid displaying anything in the row label header
} else {
Expand Down Expand Up @@ -179,13 +179,13 @@ ttt.formula <- function(x, data, ..., render, lab, caption, footnote,
f <- Formula(x)
m <- model.frame(f, data=data, na.action=na.pass)
if (is.null(dummy)) {
x <- model.part(f, data=m, lhs=1, drop=T)
x <- model.part(f, data=m, lhs=1, drop=TRUE)
xname <- as.character(f[[2]])
} else {
x <- dummy
xname <- "dummy"
}
rowvars <- model.part(f, data=m, rhs=1, drop=F)
rowvars <- model.part(f, data=m, rhs=1, drop=FALSE)
if (ncol(rowvars) == 0) {
rowvars <- NULL
if (missing(lab) || is.null(lab)) {
Expand All @@ -194,7 +194,7 @@ ttt.formula <- function(x, data, ..., render, lab, caption, footnote,
attr(lab, ".suppressrowlabels") <- TRUE
}
if (length(f)[2] > 1) {
colvars <- rev(model.part(f, data=m, rhs=2, drop=F))
colvars <- rev(model.part(f, data=m, rhs=2, drop=FALSE))
} else {
colvars <- data.frame(rep(xname, nrow(m)))
names(colvars) <- xname
Expand Down Expand Up @@ -262,23 +262,23 @@ ttt.numeric <- function(x, rowvars, colvars, ..., render, lab, caption, footnote
text <- unlist(text)
html.class <- unlist(html.class)
if (expand.along != "rows") {
text <- matrix(text, nrow=nrow(counts), byrow=T)
html.class <- matrix(html.class, nrow=nrow(counts), byrow=T)
text <- matrix(text, nrow=nrow(counts), byrow=TRUE)
html.class <- matrix(html.class, nrow=nrow(counts), byrow=TRUE)
}

a <- attributes(counts)
names(a$row.vars) <- namesOrLabels(rowvars)
names(a$col.vars) <- namesOrLabels(colvars)
if (nstats > 0) {
if (expand.along == "rows") {
counts <- counts[rep(seq_len(nrow(counts)), each=nstats),, drop=F]
counts <- counts[rep(seq_len(nrow(counts)), each=nstats),, drop=FALSE]
a$row.vars <- c(a$row.vars, setNames(list(stats), statslab))
if (missing(lab) || is.null(lab)) {
lab <- list() # Special value
}
attr(lab, ".suppressrowlabels") <- FALSE
} else {
counts <- counts[,rep(seq_len(ncol(counts)), each=nstats), drop=F]
counts <- counts[,rep(seq_len(ncol(counts)), each=nstats), drop=FALSE]
a$col.vars <- c(a$col.vars, setNames(list(stats), statslab))
}
counts[is.na(text)] <- 0
Expand Down Expand Up @@ -326,8 +326,8 @@ ttt.ftable <- function(x, text=matrix(as.character(x), nrow(x)), lab, caption, f
xrv <- attr(x, "row.vars")
xcv <- attr(x, "col.vars")

rlab <- rev(expand.grid(rev(xrv), stringsAsFactors=F))
clab <- rev(expand.grid(rev(xcv), stringsAsFactors=F))
rlab <- rev(expand.grid(rev(xrv), stringsAsFactors=FALSE))
clab <- rev(expand.grid(rev(xcv), stringsAsFactors=FALSE))

zr <- apply(x, 1, sum) == 0
zc <- apply(x, 2, sum) == 0
Expand All @@ -340,10 +340,10 @@ ttt.ftable <- function(x, text=matrix(as.character(x), nrow(x)), lab, caption, f
}

if (drop == "both") {
text <- text[!zr, !zc, drop=F]
hcls <- hcls[!zr, !zc, drop=F]
rlab <- rlab[!zr, , drop=F]
clab <- clab[!zc, , drop=F]
text <- text[!zr, !zc, drop=FALSE]
hcls <- hcls[!zr, !zc, drop=FALSE]
rlab <- rlab[!zr, , drop=FALSE]
clab <- clab[!zc, , drop=FALSE]
} else if (drop == "rows") {
text <- text[!zr, ]
hcls <- hcls[!zr, ]
Expand All @@ -357,7 +357,7 @@ ttt.ftable <- function(x, text=matrix(as.character(x), nrow(x)), lab, caption, f
collapseLabels <- function(lab) {
res <- lapply(seq_along(lab), function(i) {
z <- lab[,i]
z2 <- apply(lab[,1:i, drop=F], 1, paste0, collapse=".")
z2 <- apply(lab[,1:i, drop=FALSE], 1, paste0, collapse=".")
n <- length(z)
z[c(FALSE, z2[-1] == z2[-n])] <- ""
z
Expand Down Expand Up @@ -534,6 +534,8 @@ print.ttt <- function(x, ..., theme=getOption("ttt.theme")) {
#' @param x An object returned by \code{\link{ttt}}.
#' @param ... Further arguments passed on to \code{knitr::knit_print}.
#' @param theme A theme (either "default" or "booktabs").
#' @return Returns a \code{character} string. See \code{knitr::knit_print} for
#' how this value is used.
#' @importFrom knitr knit_print
#' @export
knit_print.ttt <- function(x, ..., theme=getOption("ttt.theme")) {
Expand Down
29 changes: 26 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
# Version 1.0

Note: I am resubmitting because I found some small errors in the vignette
and fixed them.

This is the first submission of `ttt` to CRAN.

## Fixing the following comments from reviewer and resubmitting

* From: Gregor Seyer <gregor.seyer@wu.ac.at>
* Date: Thu, 6 May 2021 09:56:56 +0200

- Please do not start the description with "This package", package name,
title or similar.

* Changed description.

- Please write TRUE and FALSE instead of T and F. (Please don't use 'T' or
'F' as vector names.)

* Done.

- Please add \value to .Rd files regarding exported methods and explain the
functions results in the documentation. Please write about the structure of
the output (class) and also what the output means. (If a function does not
return a value, please document that too, e.g. \value{No return value,
called for side effects} or similar)

Missing Rd-tags:
knit_print.ttt.Rd: \value

* \value added.

## Test environments

* Local:
Expand Down
4 changes: 4 additions & 0 deletions man/knit_print.ttt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ttt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vignettes/ttt-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ intention.
Before we start, let's load a couple of packages that we will be using:

```{r}
library(table1, quietly=T)
library(magrittr, quietly=T)
library(table1, quietly=TRUE)
library(magrittr, quietly=TRUE)
```

It is worth taking a minute to comment on these packages. The first, `table1`,
Expand Down Expand Up @@ -289,19 +289,19 @@ has been used throughout this vignette so far, and the `booktabs` theme. (More
themes may be added later.) Selecting the theme can be done using the
`ttt.theme` global option:

```{r, eval=F}
```{r, eval=FALSE}
options(ttt.theme="booktabs") # Select the "booktabs" theme
```

If we select the `booktabs` theme, our large table looks like this:

```{r, eval=F}
```{r, eval=FALSE}
ttt(x ~ R3 + R2 + R1 | C1 + C2 + C3, data=bigtable)
```

```{r, echo=F}
```{r, echo=FALSE}
css <- readLines(system.file(package="ttt", "ttt_booktabs_1.0/ttt_booktabs.css"))
css <- gsub(".Rttt ", ".Rttt-booktabs-demo ", css, fixed=T)
css <- gsub(".Rttt ", ".Rttt-booktabs-demo ", css, fixed=TRUE)
ttt(x ~ R3 + R2 + R1 | C1 + C2 + C3, data=bigtable, topclass="Rttt-booktabs-demo", css=css)
```

Expand All @@ -310,7 +310,7 @@ selectively style different tables within the same document differently using
different themes, as we appear to have done here (but it can be done with
custom styling, which is how it was done).

```{r, eval=F}
```{r, eval=FALSE}
options(ttt.theme="default") # Change back to the "default" theme
```

Expand Down

0 comments on commit 9a99dc8

Please sign in to comment.