Package 'rpkgdemo'

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

Help Index


Prepare lab data

Description

Prepare lab data for analysis. Standardizes the sex variable, joins with zipcodes data, centers and scales lab values.

Usage

prep_lab_data(x, warnings = TRUE)

Arguments

x

A data frame containing lab data with at least sex, zip, and lab value columns starting with "lab".

warnings

Logical. Whether to issue warnings for potential data issues (bad zip codes, minors, unrealistic ages). Default is TRUE.

Value

A data frame with standardized sex, joined zipcodes, and scaled lab values.

Examples

prep_lab_data(rped)

Race mapping

Description

A named character vector mapping various race categories to a harmonized variable

Usage

racemap

Format

A named character vector.

Examples

racemap
racemap["AI/AN"]
racemap["Black"]
racemap["Doesn't exist in the mapping"]
table(racemap)

Read laboratory data

Description

Read laboratory data from a file

Usage

read_labdata(file)

Arguments

file

A file path

Value

A data frame

Examples

fp <- system.file("extdata/rped.csv", package = "rpkgdemo", mustWork = TRUE)
read_labdata(fp)

RPED: R Package Example Data

Description

Simulated data for demonstrating the functionality of the rpkgdemo package.

Usage

rped

Format

A data frame with 6 columns:

  1. id: A unique identifier for each individual.

  2. sex: The sex of the individual.

  3. age: The age of the individual.

  4. zip: The ZIP code of the individual's residence.

  5. lab1: A simulated lab value from a Poisson distribution with lambda=2.

  6. lab2: A simulated lab value from a Poisson distribution with lambda=10.

Examples

rped

Standardize race variable

Description

Standardize race variable

Usage

standardize_race(x, racecol = "race")

Arguments

x

A data frame containing a race column to harmonize

racecol

The name of the race column. Default is "race".

Value

A new data frame with an additional .race_standardized column

See Also

racemap

Examples

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")

Standardize Sex Variables

Description

Maps various inputs (M, Male, f, Female) to standard HL7/ISO codes (M, F, O, U).

Usage

standardize_sex(x)

Arguments

x

A character vector of sex/gender inputs.

Value

A character vector containing "M", "F", "O", or "U".

Examples

standardize_sex(c("Male", "f", "Trans female", "nonbinary", "unknown", NA))

Suppress Low Counts for Privacy

Description

Replaces numeric counts below a threshold with a suppression character (NA).

Usage

suppress_counts(x, threshold = 5, symbol = NA)

Arguments

x

A numeric vector of counts.

threshold

Numeric. Values strictly less than this are suppressed. Default 5.

symbol

Character or NA. The symbol to use for suppression. Default is NA.

Value

A vector.

Examples

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

Description

ZIP code data from the US Postal Service.

Usage

zipcodes

Format

A data frame with three columns

  1. zip: The ZIP code.

  2. city: The U.S. city for that zip code.

  3. state: The U.S. state for that zip code.

Source

https://postalpro.usps.com/ZIP_Locale_Detail

Examples

zipcodes