Skip to contents
# 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
# 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(ClinicoPathDescriptives)
#> Registered S3 method overwritten by 'future':
#>   method               from      
#>   all.equal.connection parallelly
#> Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
#> loading 'ClinicoPathDescriptives'
#> 
#> Attaching package: 'ClinicoPathDescriptives'
#> 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") 

results <- tableone(
    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 (%)