Learn R Programming

⚠️There's a newer version (2023.9) of this package.Take me there.

bruceR

BRoadly Useful Convenient and Efficient R functions that BRing Users Concise and Elegant R data analyses.

This package includes easy-to-use functions for (1) basic R programming (e.g., set working directory to where the current file is, print strings with rich formats and colors); (2) multivariate computation (e.g., compute scale sums/means/... with reverse scoring); (3) reliability and factor analyses; (4) descriptive statistics and correlation analyses; (5) multi-factor analysis of variance (ANOVA), simple-effect analysis, and post-hoc multiple comparison; (6) tidy report of regression models and other results (to R Console and MS Word); (7) mediation and moderation analyses; and (8) additional toolbox for statistics and graphics.

Author

包寒吴霜 | Bao H.-W.-S.

E-mail: baohws@foxmail.com

Website: psychbruce.github.io

ResearchGate | GitHub | 知乎

Citation

User Guide

Release Notes

Installation

## Method 1: Install from CRAN
install.packages("bruceR")

## Method 2: Install from GitHub
install.packages("devtools")
devtools::install_github("psychbruce/bruceR", force=TRUE, upgrade=FALSE)

Tips:

  1. Please restart (close and reopen) RStudio before installation.
  2. If you see a dialog asking "Do you want to install from sources the package which needs compilation?", it would be better to choose "No" (to save your time).
  3. If you fail to install, please read carefully the warning messages and find out the key R package(s) causing the failure, manually uninstall and reinstall these R package(s), and then retry the main installation.
  4. It would be better to update R to its latest version (v4.0+).
  5. It would be better to download and install Rtools.exe on Windows system.

Package Dependency

bruceR depends on many important R packages.

Loading bruceR by library(bruceR) will also load these R packages for you:

  • [Data]:

    • rio: Data import and export (for all file formats).
    • dplyr: Data manipulation and processing.
    • tidyr: Data cleaning and reshaping.
    • stringr: Toolbox for string operation (with regular expressions).
    • forcats: Toolbox for factor manipulation (for categorical variables).
    • data.table: Advanced data.frame with higher efficiency.
  • [Stat]:

    • psych: Toolbox for psychological and psychometric research.
    • emmeans: Toolbox for estimated marginal means and contrasts.
    • effectsize: Indices of effect size and standardized parameters.
    • performance: Assessment of regression models performance.
  • [Plot]:

    • ggplot2: Data visualization.
    • ggtext: Markdown/HTML rich text format for ggplot2 (geoms and themes).
    • cowplot: Advanced toolbox for ggplot2 (arrange multiple plots and add labels).
    • see: Advanced toolbox for ggplot2 (geoms, scales, themes, and color palettes).

Main Functions in bruceR

  1. Basic R Programming

    • set.wd()
    • pkg_depend(), pkg_install_suggested()
    • formatF(), formatN()
    • Print(), Glue(), Run()
    • %^%
    • %notin%
    • %allin%, %anyin%, %nonein%, %partin%
  2. Multivariate Computation

    • SUM(), MEAN(), STD(), MODE(), COUNT(), CONSEC()
    • RECODE(), RESCALE(), RANDBETWEEN()
    • LOOKUP()
  3. Reliability and Factor analyses

    • Alpha()
    • EFA()
    • CFA()
  4. Descriptive Statistics and Correlation Analyses

    • Describe()
    • Freq()
    • Corr()
    • cor_diff()
  5. Multi-Factor ANOVA, Simple-Effect Analysis, and Post-Hoc Multiple Comparison

    • MANOVA()
    • EMMEANS()
  6. Tidy Report of Regression Models

    • model_summary()
    • GLM_summary()
    • HLM_summary()
    • HLM_ICC_rWG()
    • regress()
  7. Mediation and Moderation Analyses

    • med_summary()
    • PROCESS() (coming soon...)
  8. Additional Toolbox for Statistics and Graphics

    • grand_mean_center()
    • group_mean_center()
    • ccf_plot()
    • granger_test()
    • granger_causality()
    • theme_bruce()
    • show_colors()

Function Output

Some functions in bruceR allow table output to Microsoft Word (by setting file="xxx.doc" in the function).

bruceR FunctionOutput: R ConsoleOutput: MS Word
print_table()√ (basic)
Describe()
Freq()
Corr()√ (recommended)
Alpha()
EFA()
CFA()
MANOVA()
EMMEANS()
model_summary()√ (recommended)
med_summary()
GLM_summary()
HLM_summary()
HLM_ICC_rWG()
granger_test()
granger_causality()

Examples:

## Correlation analysis (and descriptive statistics)
Corr(airquality, file="cor.doc")

## Regression analysis
lm1=lm(Temp ~ Month + Day, data=airquality)
lm2=lm(Temp ~ Month + Day + Wind + Solar.R, data=airquality)
model_summary(list(lm1, lm2), file="reg.doc")
model_summary(list(lm1, lm2), std=TRUE, file="reg_std.doc")

Learn More From Help Pages

library(bruceR)

## Overview
help("bruceR")
help(bruceR)
?bruceR

## See help pages of functions
## (use `?function` or `help(function)`)
?set.wd
?Describe
?Freq
?Corr
?Alpha
?MEAN
?MANOVA
?EMMEANS
?model_summary
?med_summary
?GLM_summary
?HLM_summary
...

Copy Link

Version

Install

install.packages('bruceR')

Monthly Downloads

2,890

Version

0.6.4

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Han-Wu-Shuang Bao

Last Published

May 13th, 2021

Functions in bruceR (0.6.4)

Describe

Descriptive statistics (to R Console or MS Word).
HLM_summary

Tidy report of HLM (lmer and glmer models).
GLM_summary

Tidy report of GLM (lm and glm models).
CFA

Confirmatory factor analysis (CFA).
HLM_ICC_rWG

Tidy report of HLM indices: ICC(1), ICC(2), and rWG/rWG(J).
EFA

Exploratory factor analysis (EFA).
Freq

Frequency statistics (to R Console or MS Word).
Alpha

Reliability analysis (Cronbach's \(\alpha\) and McDonald's \(\omega\)).
Corr

Correlation analysis (to R Console or MS Word).
EMMEANS

Simple-effect analysis and post-hoc multiple comparison.
Print

Print strings with rich formats and colors.
RECODE

Recode a variable.
cor_diff

Test the difference between two correlations.
RESCALE

Rescale a variable (e.g., from 5-point to 7-point).
ccf_plot

Cross-correlation analysis.
dtime

Timer (compute time difference).
formatF

Format numeric values.
formatN

Format "1234" to "1,234".
%%COMPUTE%%

Multivariate computation.
RANDBETWEEN

Random sampling (like Excel's function RANDBETWEEN).
formula_expand

Expand all interaction terms in a formula.
LOOKUP

Search, match, and look up values (like Excel's functions INDEX + MATCH).
Run

Run code parsed from text.
formula_paste

Paste a formula into a string.
RGB

A simple extension of rgb().
bruceR-demodata

Demo data.
%^%

Paste strings together.
bruceR-package

bruceR: BRoadly Useful Convenient and Efficient R functions
show_colors

Show colors.
group_mean_center

Group-mean centering
regress

Regression analysis.
theme_bruce

A nice ggplot2 theme that enables Markdown/HTML rich text.
grand_mean_center

Grand-mean centering.
MANOVA

Multi-factor ANOVA.
med_summary

Tidy report of mediation analysis (to R Console or MS Word).
%nonein%

A simple extension of %in%.
p

Compute p value.
model_summary

Tidy report of regression models (to R Console or MS Word).
pkg_depend

Check dependencies of R packages.
%partin%

A simple extension of %in%.
print_table

Print a three-line table (to R Console or MS Word).
%notin%

The opposite of %in%.
pkg_install_suggested

Install suggested R packages.
rep_char

Repeat a character string for many times and paste them up.
granger_test

Granger causality test (bivariate).
%anyin%

A simple extension of %in%.
granger_causality

Granger causality test (multivariate).
scaler

Min-max scaling (min-max normalization).
%allin%

A simple extension of %in%.
set.wd

Set working directory to where the current file is.