baseverse is intended to be a relatively minimal suite of packages, supporting the use of base R with native piping.
Several functions are wrapper functions for existing base-R functions, adding support for native piping:
p_cor(): a wrapper for cor()p_glm(): a wrapper for glm()p_lm(): a wrapper for lm()p_t.test(): a wrapper for t.test()p_table(): a wrapper for table()p_wilcox.test(): a wrapper for wilcox.test()Other functions are wrapper functions for existing base-R features:
bang(): is a wrapper for !, and is similar to not() from magrittrbracket(): is a wrapper for []dollar(): is a wrapper for $, and is similar to pull() from dplyrOther functions mimic tidyverse functions:
base_match(): mimics case_match(), but returns a factor and respects the user's desired order of groupsbase_when(): mimics case_when(), but returns a factor and respects the user's desired order of groupset(): mimics count()Load the package:
library(baseverse)
This vignette will draw from the built-in nhanes data:
data(nhanes)
Table the dmdborn4 variable:
nhanes |> p_table(dmdborn4)
Create a new, labelled version of dmdborn4:
nhanes<-nhanes |> transform( country=base_match(dmdborn4,'USA'=1,'Other'=2) )
Table the new variable using p_table():
nhanes |> p_table(country)
Or, table the new variable using et():
nhanes |> et(country)
Notice that the USA group is listed first. This is, deliberately, hugely different behavior from case_match().
Summarize the lbxtc variable:
nhanes$lbxtc |> summary()
Or, using dollar():
nhanes |> dollar(lbxtc) |> summary()
Create a categorical variable for total cholesterol:
nhanes<-nhanes |> transform( cholesterol=base_when( 'Desirable' = (lbxtc<200), 'Borderline high' = (lbxtc>=200)&(lbxtc<240), 'High' = (lbxtc>=240) ) )
Table the new variable using p_table():
nhanes |> p_table(cholesterol)
Or, table the new variable using et():
nhanes |> et(cholesterol)
Notice that the Desirable group is listed first. This is, deliberately, hugely different behavior from case_when().
Fit a linear model for systolic blood pressure (bpxosy1):
model_1<-nhanes |> p_lm(bpxosy1~ridageyr+country+lbxtc)
Summarize the model:
model_1 |> summary()
Obtain 95% confidence intervals for the coefficients:
model_1 |> confint()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.