Skip to content

Commit

Permalink
address comments from CRAN reviewer.
Browse files Browse the repository at this point in the history
- no reference for the package.
- added \value into .Rd files.
  • Loading branch information
elong0527 committed Oct 27, 2023
1 parent 2d98232 commit 9580526
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^pkgdown$
^vignettes/metalite-table1.Rmd$
^vignettes/fig$
^vignettes/examples$
9 changes: 8 additions & 1 deletion R/metalite_table1.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#' "none", "listing", "table", and 'all'.
#' @param type a character value to control section title (e.g. "Subjects", "Records").
#'
#' @return a `shiny.tag.list` object that contain a `reactable` HTML widget for
#' interactive table of describptive statistics.
#'
#' @examples
#' if (interactive()) {
#' metalite_table1(~ AGE + SEX | TRT01A, data = r2rtf::r2rtf_adsl, id = "SUBJID")
Expand Down Expand Up @@ -104,7 +107,11 @@ metalite_table1 <- function(formula,
#'
#' @param x an output from `metalite_table1`.
#'
#' @return HTML string of `reactable` HTML widget for
#' interactive table of describptive statistics.
#'
#' @export
metalite_table1_to_html <- function(x) {
cat(htmltools::doRenderTags(x))
attributes(x)$browsable_html <- NULL
print(x)
}
6 changes: 5 additions & 1 deletion man/metalite_table1.Rd

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

4 changes: 4 additions & 0 deletions man/metalite_table1_to_html.Rd

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

22 changes: 22 additions & 0 deletions vignettes/examples/for-loop.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
```{r}
library(metalite.table1)
```

```{r, include = FALSE}
reactable::reactable(data.frame(x = 1))
```

```{r, results="asis"}
type <- c("Subjects", "Records")
for (i in 1:2) {
cat("### Table ", i, "\n")
tbl <- metalite_table1(~ AGE + SEX | ARM,
data = r2rtf::r2rtf_adsl,
id = "USUBJID",
type = type[i]
)
metalite_table1_to_html(tbl)
}
```
20 changes: 18 additions & 2 deletions vignettes/metalite-table1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,28 @@ metalite_table1(~ AGE + SEX | ARM,

## Rmarkdown Render

```{r, include = FALSE}
import_example <- function(file, lang = xfun::file_ext(file)) {
x = xfun::read_utf8(file.path("examples", file))
lang = tolower(lang)
if (nchar(lang) > 1) {
lang = sub('^r', '', lang)
if (lang == 'nw') lang = 'tex'
}
knitr::asis_output(paste(c(sprintf("````%s", lang), x, "````"), collapse = '\n'))
}
```

Sometimes we want to create multiple tables in a for loop,
we need to clearly call the `print` function and
we need to clearly call the `metalite_table1_to_html` function and
[output text as raw content](https://bookdown.org/yihui/rmarkdown-cookbook/results-asis.html)
by using `resutls="asis"` (e.g., `{r, results="asis"}`) in the Rmarkdown code chunk.
Create a dummy `reactable` object outside of for loop is necessary to include all
required javascript library. A full Rmarkdown example is as below.

`r import_example("for-loop.Rmd")`

```{r, results="asis"}
```{r, results="asis", echo = FALSE}
type <- c("Subjects", "Records")
for (i in 1:2) {
cat("### Table ", i, "\n")
Expand Down

0 comments on commit 9580526

Please sign in to comment.