knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
sbwtools is a package containing my most frequently used custom functions I have either written myself or borrowed from other, more skilled programmers.
Updated ci_df
and ci_boot_df
functions to use dplyr::reframe()
instead of dplyr::summarize()
,
as of dplyr
version 1.1.0
Updated on r Sys.time()
sessioninfo::platform_info()
sbwtools is only available from GitHub. Install with:
# install.packages("devtools") devtools::install_github("sbw78/sbwtools")
Credit to Kevin Ushey for the functions hh, ht, last, se. He created these functions for his .Rprofile dotfile, which you can find at his github repo.
Credit to Jacob Long for the theme_apa
used in
make_forest_plot
.
ci_df
Build a dataframe with the mean and confidence intervals of a continuous variable, with optional grouping.
library(sbwtools) library(dplyr) ci_data <- iris %>% as_tibble() %>% ci_df(., Petal.Length, Species)
ci_boot_df
Same as ci_df
, but with bootstrapped sampling
ci_boot_data <- iris %>% as_tibble() %>% ci_boot_df(., Petal.Length, Species)
custom_kable
Customized knitr::kable
output.
custom_kable(ci_data, caption = "Summarized data from iris", col.names = c("Species", "n", "Petal Length", "Lower CI", "Upper CI", "sd")) custom_kable(ci_data, caption = "Summarized data from iris", col.names = c("Species", "n", "Petal Length", "Lower CI", "Upper CI", "sd")) %>% kableExtra::footnote(general = "1000 bootstrapped samples")
format_pval
Format p-values (i.e. "< .001" for values less than .001).
fit <- lm(Sepal.Length ~ Species, data = iris) summary_df <- broom::tidy(fit) # Without formatting p-value summary_df # Formatted p-value mutate(summary_df, p.value = format_pval(p.value))
hh
and ht
hh
: Get first 5 rows and first 5 columns of a data frame or matrix
ht
: Get the first 10 rows and last 10 rows of a data frame or matrix.
Credit: Kevin Ushey
hh(iris) ht(iris)
last
Get the last element of a vector or list.
Credit: Kevin Ushey
last(letters)
make_forest_plot
Build a forest plot.
Credit: Jacob Long, author of the
jtools package
(github) from which this function
borrows the ggplot2
theme theme_apa()
.
p <- make_forest_plot(ci_data, mean_Petal.Length, Species, xlab = "Mean petal length", ylab = "Species", ci_low, ci_high) p
regex_build
Combine a character vector into a single regex list.
regex_build(c("apples", "oranges", "bananas")) regex_build(c("apples", "passion fruit", "oranges"), modifier = "multi")
se
Calculate standard error.
Credit: Kevin Ushey
se(iris$Sepal.Length)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.