
Generate a Word Document for the HiTOP-SR Assessment
Source:R/generate_docx.R
generate_docx_hitopsr.RdCreates a formatted Microsoft Word document containing the Hierarchical Taxonomy of Psychopathology - Self-Report (HiTOP-SR) items, instructions, and optional scoring keys. The 405 items are formatted into a single continuous table.
Usage
generate_docx_hitopsr(
file = "hitopsr.docx",
papersize = c("us", "a4"),
title = NULL,
include_scoring = TRUE,
include_subscales = FALSE,
font_size = 10,
font_family = "Times New Roman",
module = NULL,
renumber = TRUE,
randomize = FALSE,
descriptor = NULL,
subset = NULL
)Arguments
- file
Character string specifying the output file path. Defaults to
"hitopsr.docx".- papersize
Character string specifying the paper dimensions. Must be one of
"us"(8.5x11 inches) or"a4"(210x297 mm). Defaults to"us".- title
Character string for the document header title, printed verbatim. The default (
NULL) resolves by what the form contains:"HiTOP-SR Module (v1.0)"whenmoduleis supplied and"HiTOP-SR (v1.0)"otherwise, so a form built from a few scales is not headed as the full 405-item instrument. (default =NULL)- include_scoring
Logical. If
TRUE(default), appends a page break and the scoring instructions table.- include_subscales
Logical. If
TRUE, appends optional subscales to the scoring instructions table. Defaults toFALSE.- font_size
Numeric value specifying the base font size in points. Defaults to
10.- font_family
Character string specifying the font family to be used. Defaults to
"Times New Roman".- module
An optional
hitop_module()object restricting the form to the items of the chosen scales. Cannot be combined withinclude_subscales = TRUE. (default =NULL)- renumber
Logical. If
TRUE(default), the printed items are numbered1tondown the page, so a module form does not show the full instrument's gapped numbers. Set toFALSEto print each item's original HiTOP-SR number instead. The scoring page always uses whichever numbers are printed. This differs fromgenerate_qualtrics_hitopsr()andgenerate_redcap_hitopsr(), which never renumber, because there an item number names a collected data column.- randomize
Logical. If
TRUE, the items are printed in a random order. On a renumbered module form the document also carries a crosswalk from each printed number back to its original HiTOP-SR number, so the form is scoreable from the paper alone; that crosswalk is printed whether or notinclude_scoringappends the key. It is not printed whenmoduleisNULL(405 pairs would be one dense paragraph) or whenrenumber = FALSE(the printed numbers are already the original ones) — in both cases read the order from theitem_orderattribute described under Value. There is noseedargument: callset.seed()before this function to make an order reproducible. (default =FALSE)Scoring data collected on a shuffled form. By default
score_hitopsr()andreliability_hitopsr()expect a module's items in ascending original order — not the order a shuffled form prints them in. Data entered straight off the form has its columns in the order the form printed, its first column holding the answer to the paper's item 1. Score such columns withlayout = "printed"and a module carrying the printed order on itsitem_orderattribute: passdescriptorhere andread_module()hands that module back. Scoring printed-order columns under the default layout returns wrong scale scores and raises no error; columns already in instrument order take the default, andlayout = "printed"applied to them scrambles what was right.- descriptor
An optional path to write a module descriptor to, beside the Word file. The saved file records which scales the form covers and which instrument items they draw on, so
read_module()hands the module straight back toscore_hitopsr()at scoring time. A call passing nomodulewrites a descriptor naming every scale, describing the full administration. Withrandomize = TRUEit also records the printed order, returned on the read module'sitem_orderattribute — the record a shuffled whole-instrument form otherwise leaves nowhere, since no crosswalk is printed for one. Written before the Word file, so an unwritable path is reported before any form is produced; if the Word file then cannot be written, the descriptor is removed again, a file that was already at that path included. It must name a path of its own: an empty string, or the same path asfile, is refused rather than leaving you with no descriptor and no error. Once both files are on disk the descriptor's path is announced on the console, after the message naming the Word file. (default =NULL)- subset
Deprecated. The former name of
module; supplying it warns. Supplying bothmoduleandsubsetis an error. (default =NULL)
Value
Invisibly returns the path to the created file (file), carrying an
item_order attribute: the original HiTOP-SR item numbers in the order
they were printed. It is present on every call, and is simply ascending
unless randomize = TRUE.
See also
write_module() and read_module() for the descriptor file.
Examples
# \donttest{
# Write a HiTOP-SR paper form to a temporary Word document
generate_docx_hitopsr(file = tempfile(fileext = ".docx"))
#> ✔ Document successfully created at /tmp/RtmpH4gJGP/file1a661b7e8c9d.docx
# A module containing only two scales, printed as items 1 to 8
generate_docx_hitopsr(
file = tempfile(fileext = ".docx"),
module = hitop_module("hitopsr", c("Agoraphobia", "Appetite Loss"))
)
#> ✔ Document successfully created at /tmp/RtmpH4gJGP/file1a66d983b13.docx
# The same module keeping the full instrument's own item numbers
generate_docx_hitopsr(
file = tempfile(fileext = ".docx"),
module = hitop_module("hitopsr", c("Agoraphobia", "Appetite Loss")),
renumber = FALSE
)
#> ✔ Document successfully created at /tmp/RtmpH4gJGP/file1a665498bb66.docx
# A shuffled form; the scoring page carries the crosswalk back
set.seed(1)
out <- generate_docx_hitopsr(
file = tempfile(fileext = ".docx"),
module = hitop_module("hitopsr", c("Agoraphobia", "Appetite Loss")),
randomize = TRUE
)
#> ✔ Document successfully created at /tmp/RtmpH4gJGP/file1a6639267a4b.docx
attr(out, "item_order")
#> [1] 66 144 389 109 260 118 291 202
# The same form with a descriptor saved beside it; the descriptor carries
# the printed order, so the collected columns can be put back in order
# without keeping a note by hand
f <- tempfile(fileext = ".json")
generate_docx_hitopsr(
file = tempfile(fileext = ".docx"),
module = hitop_module("hitopsr", c("Agoraphobia", "Appetite Loss")),
randomize = TRUE,
descriptor = f
)
#> ✔ Document successfully created at /tmp/RtmpH4gJGP/file1a665d0abf15.docx
#> ✔ Module descriptor successfully written to /tmp/RtmpH4gJGP/file1a662eb543ef.json
attr(read_module(f), "item_order")
#> [1] 109 118 291 66 202 144 389 260
# }