Skip to content

Commit 6e8a443

Browse files
committed
further doc fixes
1 parent 47ccd92 commit 6e8a443

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+236
-197
lines changed

R/codebook.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' If the dataset has metadata (attributes) set on its variables, these will be
77
#' used to make the codebook more informative. Examples are item, value, and
88
#' missing labels.
9-
#' Data frames imported via [haven::read_dta], [haven::read_sav], or from
9+
#' Data frames imported via [haven::read_dta()], [haven::read_sav()], or from
1010
#' [formr.org](https://formr.org) will have these attributes in the right format.
1111
#' By calling this function inside a knitr code chunk, the
1212
#' codebook will become part of the document you are generating.
@@ -142,6 +142,8 @@ codebook <- function(results, reliabilities = NULL,
142142

143143
#' Codebook survey overview
144144
#'
145+
#' An overview of the number of rows and groups, and of the durations participants
146+
#' needed to respond (if those data are available).
145147
#'
146148
#' @param results a data frame which has the following columns: session, created, modified, expired, ended
147149
#' @param survey_repetition defaults to single (other values: repeated_once, repeated_many). controls whether internal consistency, retest reliability or multilevel reliability is computed
@@ -194,6 +196,7 @@ codebook_survey_overview <- function(results, survey_repetition = "single",
194196

195197
#' Codebook missingness
196198
#'
199+
#' An overview table of missingness patterns generated using [md_pattern()].
197200
#'
198201
#' @param results a data frame
199202
#' @param indent add # to this to make the headings in the components lower-level. defaults to beginning at h2
@@ -215,7 +218,8 @@ codebook_missingness <- function(results, indent = "##") {
215218

216219
#' Metadata as JSON-LD
217220
#'
218-
#' Echo a list of a metadata as JSON-LD in a script tag.
221+
#' Echo a list of a metadata, generated using [metadata_list()] as JSON-LD in a
222+
#' script tag.
219223
#'
220224
#' @param results a data frame, ideally with attributes set on variables
221225
#' @export
@@ -234,7 +238,8 @@ metadata_jsonld <- function(results) {
234238

235239
#' Tabular codebook
236240
#'
237-
#' Renders a tabular codebook including attributes and data summaries.
241+
#' Renders a tabular codebook including attributes and data summaries. The table
242+
#' is generated using [DT::datatable()] and can be exported to CSV, Excel, etc.
238243
#'
239244
#'
240245
#' @param results a data frame, ideally with attributes set on variables
@@ -312,7 +317,7 @@ codebook_component_single_item <- function(item, item_name, indent = '##') {
312317
#' Codebook metadata table
313318
#'
314319
#' will generate a table combining metadata from variable attributes
315-
#' with data summaries generated using skimr
320+
#' with data summaries generated using [skimr::skim_to_wide()]
316321
#'
317322
#' @param results a data frame, ideally with attributes set on variables
318323
#'
@@ -483,7 +488,8 @@ metadata_list <- function(results) {
483488

484489
skim_to_wide_labelled <- function(...) {
485490
suppressMessages(
486-
skimr::skim_with(labelled = skimr::get_skimmers()$factor)
491+
skimr::skim_with(labelled = skimr::get_skimmers()$factor,
492+
labelled_spss = skimr::get_skimmers()$factor)
487493
)
488494
on.exit(skimr::skim_with_defaults())
489495
skimr::skim_to_wide(...)

R/correct_attributes.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @param only_labelled_missings don't set values to missing if there's no label for them
99
#' @param negative_values_are_missing by default we label negative values as missing
1010
#' @param ninety_nine_problems SPSS users often store values as 99/999, should we do this for values with 5*MAD of the median
11-
#' @param learn_from_labels if there are labels for missings of the form \preformatted{[-1]} no answer, set -1 in the data to the corresponding tagged missing
11+
#' @param learn_from_labels if there are labels for missings of the form `[-1] no answer`, set -1 in the data to the corresponding tagged missing
1212
#' @param missing also set these values to missing (or enforce for 99/999 within 5*MAD)
1313
#' @param non_missing don't set these values to missing
1414
#' @param vars only edit these variables
@@ -124,7 +124,7 @@ detect_missings <- function(data, only_labelled_missings = TRUE,
124124
#'
125125
#' You can use this function if some of your items have lost their attributes during wrangling
126126
#' Variables have to have the same name (Duh) and no attributes should be overwritten.
127-
#' But use with care.
127+
#' But use with care. Similar to [labelled::copy_labels()].
128128
#'
129129
#'
130130
#' @param df_no_attributes the data frame with missing attributes
@@ -156,8 +156,7 @@ rescue_attributes <- function(df_no_attributes, df_with_attributes) {
156156
#' Detect item scales
157157
#'
158158
#' Did you create aggregates of items like this
159-
#' scale <- scale_1 + scale_2R + scale_3R
160-
#' ?
159+
#' `scale <- scale_1 + scale_2R + scale_3R`?
161160
#' If you run this function on a dataset, it will detect these
162161
#' relationships and set the appropriate attributes. Once they are set,
163162
#' the codebook package can perform reliability computations for you.
@@ -207,7 +206,7 @@ detect_scales <- function(data, quiet = FALSE) {
207206

208207
#' Zap attributes
209208
#'
210-
#' Modelled on havens zap_labels, but more encompassing. By default removes
209+
#' Modelled on [haven::zap_labels()], but more encompassing. By default removes
211210
#' the following attributes:
212211
#' format.spss, format.sas, format.stata, label, labels, na_values, na_range,
213212
#' display_width
@@ -258,7 +257,7 @@ zap_attributes.data.frame <- function(x, attributes = NULL) {
258257

259258
#' Zap variable label
260259
#'
261-
#' Modelled on havens zap_labels, zaps variable labels.
260+
#' Modelled on [haven::zap_labels()], zaps variable labels (not value labels).
262261
#'
263262
#' @param x the data frame or variable
264263
#' @export
@@ -270,6 +269,6 @@ zap_label.data.frame <- function(x) {
270269
x
271270
}
272271
zap_label.default <- function(x) {
273-
attributes(x)$label <- NULL
272+
attr(x, "label") <- NULL
274273
x
275274
}

R/misc.R

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ require_package <- function(package) {
1414

1515
#' Missing data patterns
1616
#'
17-
#' Generate missingness patterns using mice, with options to reduce
18-
#' the complexity of the output.
17+
#' Generate missingness patterns using [mice::md.pattern()],
18+
#' with options to reduce the complexity of the output.
1919
#'
2020
#' @param data the dataset
2121
#' @param only_vars_with_missings defaults to TRUE, omitting variables that have no missings
22-
#' @param min_freq mininum number of rows to have this missingness pattern
22+
#' @param min_freq minimum number of rows to have this missingness pattern
2323
#' @export
2424
#' @examples
2525
#' data("nhanes", package = "mice")
@@ -133,3 +133,36 @@ export_table <- function(df) {
133133
pageLength = 200
134134
))
135135
}
136+
137+
138+
139+
140+
#' Summary function for labelled vector
141+
#'
142+
#'
143+
#' @param object a labelled vector
144+
#' @param ... passed to summary.factor
145+
#'
146+
#' @export
147+
#' @examples
148+
#' example("labelled", "haven")
149+
#' summary(x)
150+
#'
151+
summary.labelled <- function(object, ...) {
152+
summary(haven::as_factor(object, levels = "both"), ...)
153+
}
154+
155+
#' Summary function for labelled_spss vector
156+
#'
157+
#'
158+
#' @param object a labelled_spss vector
159+
#' @param ... passed to summary.factor
160+
#'
161+
#' @export
162+
#' @examples
163+
#' example("labelled", "haven")
164+
#' summary(x)
165+
#'
166+
summary.labelled_spss <- function(object, ...) {
167+
summary(haven::as_factor(object, levels = "both"), ...)
168+
}

R/plot_helpers.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#' Derive a likert object from items
22
#'
33
#' Pass a data.frame containing several items composing one scale, get a
4-
#' likert object, which you can plot. Intelligently makes use of labels and value labels if present.
4+
#' [likert::likert()] object, which you can plot.
5+
#' Intelligently makes use of labels and value labels if present.
56
#'
67
#' @param items a data frame of items composing one scale
78
#'

R/psych_print.R

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#' Pretty-print a psych::alpha object
1+
#' Pretty-print a Cronbach's alpha object
22
#'
3-
#' Make the tables HTML instead of code.
3+
#' Turn a [psych::alpha()] object into HTML tables.
44
#'
55
#' @param x a psych alpha object
66
#' @param indent add # to this to make the headings in the components lower-level. defaults to beginning at h5
@@ -15,9 +15,9 @@ knit_print.alpha <- function(x, indent = '#####', ...) {
1515
asis_knit_child(require_file("_knit_print_psych.Rmd"))
1616
}
1717

18-
#' Print a psych::multilevel.reliability object for knitr
18+
#' Print a [psych::multilevel.reliability()] object for knitr
1919
#'
20-
#' Just prints the normal output.
20+
#' Just prints the normal output of [psych::multilevel.reliability()].
2121
#'
2222
#' @param x a psych alpha object
2323
#' @param indent add # to this to make the headings in the components lower-level. defaults to beginning at h5
@@ -35,9 +35,9 @@ knit_print.multilevel <- function(x, indent = '#####', ...) {
3535
}
3636

3737

38-
#' Print a stats::cor.test object for knitr
38+
#' Print a [stats::cor.test()] object for knitr
3939
#'
40-
#' Just prints the normal output.
40+
#' Just prints the normal output of [stats::cor.test()].
4141
#'
4242
#' @param x a psych alpha object
4343
#' @param indent add # to this to make the headings in the components lower-level. defaults to beginning at h5
@@ -52,33 +52,3 @@ knit_print.htest <- function(x, indent = '#####', ...) {
5252
paste0(utils::capture.output(print(x)), collapse = "\n"),
5353
"\n```\n\n\n"))
5454
}
55-
56-
#' Summary function for labelled vector
57-
#'
58-
#'
59-
#' @param object a labelled vector
60-
#' @param ... passed to summary.factor
61-
#'
62-
#' @export
63-
#' @examples
64-
#' example("labelled", "haven")
65-
#' summary(x)
66-
#'
67-
summary.labelled <- function(object, ...) {
68-
summary(haven::as_factor(object, levels = "both"), ...)
69-
}
70-
71-
#' Summary function for labelled_spss vector
72-
#'
73-
#'
74-
#' @param object a labelled_spss vector
75-
#' @param ... passed to summary.factor
76-
#'
77-
#' @export
78-
#' @examples
79-
#' example("labelled", "haven")
80-
#' summary(x)
81-
#'
82-
summary.labelled_spss <- function(object, ...) {
83-
summary(haven::as_factor(object, levels = "both"), ...)
84-
}

R/reliability.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#' Compute reliabilities
22
#'
33
#' If you pass the object resulting from a call to formr_results to this function, it will compute reliabilities for each scale.
4-
#' Internally, each reliability computation is passed to a future. If you are calculating multilevel reliabilities, it may be worthwhile to parallelise this operation using future::plan
5-
#' If you don't plan on any complicated parallelisation, you probably do not need to call this function directly, but can rely on it being automatically called during codebook generation.
4+
#' Internally, each reliability computation is passed to a [future::future()].
5+
#' If you are calculating multilevel reliabilities, it may be worthwhile to
6+
#' parallelise this operation using [future::plan()].
7+
#' If you don't plan on any complicated parallelisation, you probably do not
8+
#' need to call this function directly, but can rely on it being automatically
9+
#' called during codebook generation.
610
#' If you do plan to do that, you can pass the results of this operation to the codebook function.
711
#'
812
#' @param results a formr results table with attributes set on items and scales

R/rmarkdown_helpers.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#'
33
#' This slightly modifies the [knitr::knit_child()] function to have different defaults.
44
#' - the environment defaults to the calling environment.
5-
#' - the output receives the class knit_asis, so that the output will be rendered "as is" by knitr when calling inside a chunk (no need to set results='asis' as a chunk option).
6-
#' - defaults to quiet = TRUE
5+
#' - the output receives the class `knit_asis`, so that the output will be rendered "as is" by knitr when calling inside a chunk (no need to set `results='asis'` as a chunk option).
6+
#' - defaults to `quiet = TRUE`
77
#'
8-
#' Why default to the calling environment? Typically this function defaults to the global environment. This makes sense if you want to use knit_children in the same context as the rest of the document.
9-
#' However, you may also want to use knit_children inside functions to e.g. summarise a regression using a set of commands (e.g. plot some diagnostic graphs and a summary for a regression nicely formatted).
8+
#' Why default to the calling environment? Typically this function defaults to the global environment. This makes sense if you want to use knit children in the same context as the rest of the document.
9+
#' However, you may also want to use knit children inside functions to e.g. summarise a regression using a set of commands (e.g. plot some diagnostic graphs and a summary for a regression nicely formatted).
1010
#'
1111
#' Some caveats:
12-
#' - the function has to return to the top-level. There's no way to [cat()] this from loops or an if-condition without without setting results='asis'. You can however concatenate these objects with [paste.knit_asis()]
12+
#' - the function has to return to the top-level. There's no way to [cat()] this from loops or an if-condition without without setting `results='asis'`. You can however concatenate these objects with [paste.knit_asis()]
1313
#'
1414
#'
1515
#' @param input if you specify a file path here, it will be read in before being passed to knitr (to avoid a working directory mess)
@@ -71,13 +71,13 @@ asis_knit_child <- function(input = NULL, text = NULL, ...,
7171

7272
#' Paste and output as is (render markup)
7373
#'
74-
#' Helper function for knit_asis objects, useful when e.g. [asis_knit_child()] was used in a loop.
74+
#' Helper function for `knit_asis` objects, useful when e.g. [asis_knit_child()] was used in a loop.
7575
#'
76-
#' Works like [paste()] with both the sep and the collapse argument set to two empty lines
76+
#' Works like [base::paste()] with both the sep and the collapse argument set to two empty lines
7777
#'
78-
#' @param ... passed to [paste()]
79-
#' @param sep defaults to two empty lines, passed to [paste()]
80-
#' @param collapse defaults to two empty lines, passed to [paste()]
78+
#' @param ... passed to [base::paste()]
79+
#' @param sep defaults to two empty lines, passed to [base::paste()]
80+
#' @param collapse defaults to two empty lines, passed to [base::paste()]
8181
#'
8282
#' @export
8383
#' @examples
@@ -86,7 +86,7 @@ paste.knit_asis <- function(..., sep = "\n\n\n", collapse = "\n\n\n") {
8686
knitr::asis_output(paste(..., sep = sep, collapse = collapse))
8787
}
8888

89-
#' Print new lines in knit_asis outputs
89+
#' Print new lines in `knit_asis` outputs
9090
#'
9191
#' @param x the knit_asis object
9292
#' @param ... ignored
@@ -101,12 +101,14 @@ print.knit_asis <- function(x, ...) {
101101
#' Render codebook based on file
102102
#'
103103
#'
104-
#' Render text
104+
#' Submit a data file and an rmarkdown template as a file to generate a codebook.
105+
#' Used chiefly in the webapp.
105106
#'
106-
#' @param file file to make codebook from (sav, rds, dta, etc.)
107+
#' @param file path to a file to make codebook from (sav, rds, dta, por, xpt, csv, csv2, tsv, etc.)
107108
#' @param text codebook template
108109
#' @param remove_file whether to remove file after rendering
109110
#' @param ... all other arguments passed to [rmarkdown::render()]
111+
#' @md
110112
#'
111113
#' @export
112114

cran-comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This is a second resubmission. In this version I have:
1111
It causes an error during checking, probably because it indirectly includes
1212
an htmlwidget. It works fine in non-example use (tests, vignettes,
1313
interactively). Therefore, I wrapped the example in dontrun.
14-
* slightly changed the docs to be clearer
14+
* slightly changed the docs to be clearer and use markdown to link functions
1515

1616
In the first resubmission I
1717

docs/articles/codebook.html

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-1.49 KB
Loading

0 commit comments

Comments
 (0)