Shared core utilities for the family of statistical software to R Markdown converter packages:
# Install from the monorepo
devtools::install("pkg/stat2rmarkdown")| Function | Description |
|---|---|
%||% |
Null-coalescing operator |
quote_var() |
Backtick-quotes variable names with special characters |
create_output_dir() |
Creates timestamped output directories |
validate_vars() |
Validates variable names exist in a data frame |
safe_as_numeric() |
Safe numeric conversion from factor/character/labelled |
log_message() |
Timestamped logging utility |
| Function | Description |
|---|---|
generate_yaml_header() |
Creates YAML front matter for html_document output |
generate_setup_chunk() |
Creates knitr setup chunk with package loading |
generate_session_footer() |
Creates sessionInfo() footer section |
library(stat2rmarkdown)
# Quote variables with special characters
quote_var("income (USD)")
#> "`income (USD)`"
# Generate R Markdown components
yaml <- generate_yaml_header("My Conversion", author = "Generated by spss2rmarkdown")
setup <- generate_setup_chunk(packages = c("haven", "dplyr", "fixest"))
footer <- generate_session_footer(tool_name = "spss2rmarkdown")
# Assemble a document
rmd_content <- paste(yaml, setup, "# Analysis\n\n...\n", footer, sep = "\n")MIT