# For vignette demonstration, create a sample if 'histopathology' isn't loaded
if (!exists("histopathology")) {
set.seed(123)
histopathology <- data.frame(
Age = as.integer(rnorm(100, 60, 10)),
Sex = factor(sample(c("Male", "Female"), 100, replace = TRUE)),
Grade = factor(sample(c("Low", "High"), 100, replace = TRUE, prob = c(0.7, 0.3))),
TumorSize = rnorm(100, 30, 10),
LVI = factor(sample(c("Present", "Absent", NA), 100, replace = TRUE, prob = c(0.2, 0.7, 0.1)))
)
}
head(histopathology)
#> Age Sex Grade TumorSize LVI
#> 1 54 Female High 51.98810 Absent
#> 2 57 Female Low 43.12413 Absent
#> 3 75 Female High 27.34855 Absent
#> 4 60 Male High 35.43194 Absent
#> 5 61 Female Low 25.85660 Absent
#> 6 77 Female Low 25.23753 Present
Vignette: Generating a ‘Table 1’ with ClinicoPathDescriptives
2025-06-30
Source:vignettes/clinicopath-descriptives-02-tableone.qmd
# This code simulates how the jamovi module would be called in an R environment.
# You would need the ClinicoPathDescriptives package installed and dplyr for vars().
# Alternatively, pass variables as a character vector: c("Age", "Sex", "Grade", "TumorSize", "LVI")
library(ClinicoPath)
#> Registered S3 method overwritten by 'future':
#> method from
#> all.equal.connection parallelly
#> Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
#> loading 'ClinicoPath'
#> Warning: replacing previous import 'cutpointr::roc' by 'pROC::roc' when loading
#> 'ClinicoPath'
#> Warning: replacing previous import 'cutpointr::auc' by 'pROC::auc' when loading
#> 'ClinicoPath'
#> Warning: replacing previous import 'magrittr::extract' by 'tidyr::extract' when
#> loading 'ClinicoPath'
#> Warning in check_dep_version(): ABI version mismatch:
#> lme4 was built with Matrix ABI version 1
#> Current Matrix ABI version is 0
#> Please re-install lme4 from source or restore original 'Matrix' package
#> Warning: replacing previous import 'jmvcore::select' by 'dplyr::select' when
#> loading 'ClinicoPath'
#> Registered S3 methods overwritten by 'ggpp':
#> method from
#> heightDetails.titleGrob ggplot2
#> widthDetails.titleGrob ggplot2
#> Warning: replacing previous import 'DataExplorer::plot_histogram' by
#> 'grafify::plot_histogram' when loading 'ClinicoPath'
#> Warning: replacing previous import 'ROCR::plot' by 'graphics::plot' when
#> loading 'ClinicoPath'
#> Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
#> loading 'ClinicoPath'
#> Warning: replacing previous import 'tibble::view' by 'summarytools::view' when
#> loading 'ClinicoPath'
#>
#> Attaching package: 'ClinicoPath'
#> The following object is masked _by_ '.GlobalEnv':
#>
#> histopathology
library(dplyr) # For the vars() helper, not strictly needed if using character vector
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# Ensure the data is available (e.g., from the package or your own)
# data(histopathology, package = "ClinicoPathDescriptives")
<- tableone(
results data = histopathology,
vars = vars(Age, Sex, Grade, LVI), # From dplyr
# Or: vars = c("Age", "Sex", "Grade", "LVI"),
sty = "t2", # This corresponds to gtsummary
excl = FALSE # Do not exclude NAs for this example to show how they are handled
)#>
|
| | 0%
|
|......................................................................| 100%
#>
|
| | 0%
|
|......................................................................| 100%
# To render in a Quarto/R Markdown document for HTML output:
# The object 'results$tablestyle2' (for gtsummary) contains HTML.
# If results$tablestyle2 is a pre-rendered HTML string or kable object:
# htmltools::HTML(results$tablestyle2$content) # or just results$tablestyle2 if it's already raw HTML
# In an interactive RStudio session, it might print directly to the Viewer.
# Within jamovi, the HTML table is rendered automatically.
htmltools::HTML(results$tablestyle2$content)
Characteristic | N = 100 |
---|---|
Age | 60 (55, 67) |
Sex | |
Female | 49 (49%) |
Male | 51 (51%) |
Grade | |
High | 31 (31%) |
Low | 69 (69%) |
LVI | |
Absent | 65 (71%) |
Present | 27 (29%) |
Unknown | 8 |
1 Median (Q1, Q3); n (%) |