Package 'prmisc'

Title: Miscellaneous Printing of Numeric and Statistical Output in R Markdown and Quarto Documents
Description: Miscellaneous printing of numeric or statistical results in R Markdown or Quarto documents according to guidelines of the "Publication Manual" of the American Psychological Association (2020, ISBN: 978-1-4338-3215-4). These guidelines are usually referred to as APA style (<https://apastyle.apa.org/>) and include specific rules on the formatting of numbers and statistical test results. APA style has to be implemented when submitting scientific reports in a wide range of research fields, especially in the social sciences. The default output of numbers in the R console or R Markdown and Quarto documents does not meet the APA style requirements, and reformatting results manually can be cumbersome and error-prone. This package covers the automatic conversion of R objects to textual representations that meet the APA style requirements, which can be included in R Markdown or Quarto documents. It covers some basic statistical tests (t-test, ANOVA, correlation, chi-squared test, Wilcoxon test) as well as some basic number printing manipulations (formatting p-values, removing leading zeros for numbers that cannot be greater than one, and others). Other packages exist for formatting numbers and tests according to the APA style guidelines, such as 'papaja' (<https://cran.r-project.org/package=papaja>) and 'apa' (<https://cran.r-project.org/package=apa>), but they do not offer all convenience functionality included in 'prmisc'. The vignette has an overview of most of the functions included in the package.
Authors: Martin Papenberg [aut, cre] , Juliane V. Nagel [aut]
Maintainer: Martin Papenberg <[email protected]>
License: MIT + file LICENSE
Version: 0.0.3
Built: 2025-03-13 13:30:01 UTC
Source: https://github.com/m-py/prmisc

Help Index


Printing a specified number of decimals and ignore leading zeros

Description

Printing a specified number of decimals and ignore leading zeros

Usage

decimals_only(x, decimals = 2, decimals1 = FALSE)

Arguments

x

the values to be printed

decimals

how many decimals are to be printed. Defaults to 2.

decimals1

Boolean - should a value of exactly 1 be converted to 1.00. Defaults to FALSE.

Value

Character vector of length length(x). The number(s) in the required format.

Author(s)

Martin Papenberg [email protected]

Examples

decimals_only(c(0.23456, 0.873, 0.3456), decimals = 3)

Force printing a specified number of decimals for a number

Description

Force printing a specified number of decimals for a number

Usage

force_decimals(x, decimals = 2, round_zero = TRUE)

Arguments

x

the numeric values to be printed

decimals

how many decimals are to be printed. Defaults to 2.

round_zero

whether small values should be rounded to zero or whether they should be displayed as e.g. < .01. See details. Defaults to TRUE.

Details

By default, force_decimals() will round numbers that are small enough down to zero, e.g., 0.0004 will be rounded to 0.00. If round_zero = FALSE, force_decimals(0.0004) will return "< 0.01" instead. See examples.

Value

Character vector of length length(x). The number(s) in the required format.

Author(s)

Martin Papenberg [email protected]

Examples

force_decimals(c(1.23456, 0.873, 2.3456))
force_decimals(c(1.23456, 0.873, 2.3456), 3)

force_decimals(c(0.004, 0.001, 0.0005, 0.02))
force_decimals(c(0.004, 0.001, 0.0005, 0.02), round_zero = FALSE)
force_decimals(c(0.004, 0.001, 0.0005, 0.02), 3, round_zero = FALSE)

Print a number having a specified number of digits or as integer

Description

Print a number having a specified number of digits or as integer

Usage

force_or_cut(x, decimals = 2)

Arguments

x

A vector of numbers

decimals

The number of digits that should be printed if x is a decimal number. Defaults to 2.

Details

If x integer, only the integer is printed, if x is a decimal number, the decimals are printed

Value

Character vector of length length(x). The number(s) in the required format.

Author(s)

Martin Papenberg [email protected]

Examples

force_or_cut(c(1:3, 1.23456, 0.873, 2.3456))

Format a p-value according to APA standards

Description

Format a p-value according to APA standards

Usage

format_p(pvalues, decimals = 3, numbers_only = FALSE, latex = TRUE)

Arguments

pvalues

The p-values

decimals

The number of decimals to be printed

numbers_only

Logical, indicates whether the p-values should be printed without the accompanying p. Defaults to FALSE.

latex

Logical, indicates whether the p-values should be printed with or without $ around it. Defaults to TRUE.

Value

Character vector of length length(pvalues). A string representation of the p value(s) to be used in Rmarkdown documents.

Examples

# Format a p-value, default is 3 decimals
format_p(0.03123)
format_p(0.000001231)
format_p(0.000001231, decimals = 2)
format_p(0.3123, decimals = 2)
format_p(0.3123, latex = FALSE)
# Format several p-values with one function call
format_p(c(0.3123, 0.001, 0.00001, 0.19))
format_p(c(.999, .9999, 1))
format_p(c(0.3123, 0.001, 0.00001, 0.19, .99999), numbers_only = TRUE)