| Title: | A demo package for building R packages |
|---|---|
| Description: | A package to demonstrate building an R package to accompany a workshop on building R packages in Positron. See the getting started vignette for details. |
| Authors: | Stephen Turner [aut, cre] (ORCID: <https://orcid.org/0000-0001-9140-9028>) |
| Maintainer: | Stephen Turner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-05-23 15:12:26 UTC |
| Source: | https://github.com/stephenturner/rpkgdemo |
Prepare lab data for analysis. Standardizes the sex variable, joins with zipcodes data, centers and scales lab values.
prep_lab_data(x, warnings = TRUE)prep_lab_data(x, warnings = TRUE)
x |
A data frame containing lab data with at least |
warnings |
Logical. Whether to issue warnings for potential data issues (bad zip codes, minors, unrealistic ages). Default is |
A data frame with standardized sex, joined zipcodes, and scaled lab values.
prep_lab_data(rped)prep_lab_data(rped)
A named character vector mapping various race categories to a harmonized variable
racemapracemap
A named character vector.
racemap racemap["AI/AN"] racemap["Black"] racemap["Doesn't exist in the mapping"] table(racemap)racemap racemap["AI/AN"] racemap["Black"] racemap["Doesn't exist in the mapping"] table(racemap)
Read laboratory data from a file
read_labdata(file)read_labdata(file)
file |
A file path |
A data frame
fp <- system.file("extdata/rped.csv", package = "rpkgdemo", mustWork = TRUE) read_labdata(fp)fp <- system.file("extdata/rped.csv", package = "rpkgdemo", mustWork = TRUE) read_labdata(fp)
Simulated data for demonstrating the functionality of the rpkgdemo package.
rpedrped
A data frame with 6 columns:
id: A unique identifier for each individual.
sex: The sex of the individual.
age: The age of the individual.
zip: The ZIP code of the individual's residence.
lab1: A simulated lab value from a Poisson distribution with lambda=2.
lab2: A simulated lab value from a Poisson distribution with lambda=10.
rpedrped
Standardize race variable
standardize_race(x, racecol = "race")standardize_race(x, racecol = "race")
x |
A data frame containing a race column to harmonize |
racecol |
The name of the race column. Default is "race". |
A new data frame with an additional .race_standardized column
set.seed(123) mydata <- data.frame(reported_race=sample(names(racemap), 20, replace=TRUE)) mydata$reported_race[15] <- "Martian" mydata standardize_race(mydata, racecol="reported_race")set.seed(123) mydata <- data.frame(reported_race=sample(names(racemap), 20, replace=TRUE)) mydata$reported_race[15] <- "Martian" mydata standardize_race(mydata, racecol="reported_race")
Maps various inputs (M, Male, f, Female) to standard HL7/ISO codes (M, F, O, U).
standardize_sex(x)standardize_sex(x)
x |
A character vector of sex/gender inputs. |
A character vector containing "M", "F", "O", or "U".
standardize_sex(c("Male", "f", "Trans female", "nonbinary", "unknown", NA))standardize_sex(c("Male", "f", "Trans female", "nonbinary", "unknown", NA))
Replaces numeric counts below a threshold with a suppression character (NA).
suppress_counts(x, threshold = 5, symbol = NA)suppress_counts(x, threshold = 5, symbol = NA)
x |
A numeric vector of counts. |
threshold |
Numeric. Values strictly less than this are suppressed. Default 5. |
symbol |
Character or |
A vector.
suppress_counts(c(1, 3, 5, 7, 9)) suppress_counts(c(10, 20, 3, 4, 5), threshold = 10) suppress_counts(1:10, threshold = 5, symbol = "*")suppress_counts(c(1, 3, 5, 7, 9)) suppress_counts(c(10, 20, 3, 4, 5), threshold = 10) suppress_counts(1:10, threshold = 5, symbol = "*")
ZIP code data from the US Postal Service.
zipcodeszipcodes
A data frame with three columns
zip: The ZIP code.
city: The U.S. city for that zip code.
state: The U.S. state for that zip code.
https://postalpro.usps.com/ZIP_Locale_Detail
zipcodeszipcodes