# rpkgdemo This rpkgdemo package serves as a demonstration of how to structure an R package. View the full tutorial in the vignette: [`vignette("rpkgdemo")`](https://stephenturner.github.io/rpkgdemo/articles/rpkgdemo.md). To follow along the full tutorial you’ll need [**R**](https://www.r-project.org/), [**Positron**](https://positron.posit.co/), [**RTools**](https://cran.r-project.org/bin/windows/Rtools/) (if you’re on Windows), the following packages installed: ``` r install.packages(c( "pak", "usethis", "devtools", "roxygen2", "testthat", "knitr", "rmarkdown", "pkgdown", "available", "dplyr", "janitor", "readxl", "stringr", "covr", "DT", "htmltools", "here" )) ``` ## Installation To install rpkgdemo, run: ``` r devtools::install_github("stephenturner/rpkgdemo") ``` ## Example First, let’s load the package: ``` r library(rpkgdemo) ``` Standardize sex variables: ``` r standardize_sex(c("Male", "f", "Trans female", "nonbinary", "unknown", NA)) #> [1] "M" "F" "O" "O" "U" "U" ``` Read in some laboratory data: ``` r fp <- system.file("extdata/rped.csv", package = "rpkgdemo", mustWork = TRUE) labdat <- read_labdata(fp) labdat #> # A tibble: 1,000 × 6 #> id sex age zip lab1 lab2 #> #> 1 1 male 26 12345 4 13 #> 2 2 trans male 12 20108 2 12 #> 3 3 unk 130 20108 1 8 #> 4 4 unk 26 20109 1 13 #> 5 5 F 38 20109 5 13 #> 6 6 female 25 20109 0 15 #> 7 7 M 49 20110 6 12 #> 8 8 M 55 20111 4 10 #> 9 9 unk 55 20111 7 7 #> 10 10 F 30 20112 3 12 #> # ℹ 990 more rows ``` Prepare that data for analysis by annotating with city and state using the zip code, standardizing sex, and normalizing lab values: ``` r prep_lab_data(labdat) #> Warning in prep_lab_data(labdat): Found 1 bad zip code(s). #> Warning in prep_lab_data(labdat): Found 1 minor(s) in dataset. #> Warning in prep_lab_data(labdat): Found 1 unrealistic age(s) in dataset. #> # A tibble: 1,000 × 8 #> id sex age zip lab1 lab2 city state #> #> 1 1 M 26 12345 1.48 0.930 #> 2 2 O 12 20108 0.0623 0.620 Manassas VA #> 3 3 U 130 20108 -0.646 -0.623 Manassas VA #> 4 4 U 26 20109 -0.646 0.930 Manassas VA #> 5 5 F 38 20109 2.19 0.930 Manassas VA #> 6 6 F 25 20109 -1.35 1.55 Manassas VA #> 7 7 M 49 20110 2.90 0.620 Manassas VA #> 8 8 M 55 20111 1.48 -0.00155 Manassas VA #> 9 9 U 55 20111 3.60 -0.933 Manassas VA #> 10 10 F 30 20112 0.771 0.620 Manassas VA #> # ℹ 990 more rows ``` View the full tutorial in the vignette: [`vignette("rpkgdemo")`](https://stephenturner.github.io/rpkgdemo/articles/rpkgdemo.md). # Package index ## All functions - [`prep_lab_data()`](https://stephenturner.github.io/rpkgdemo/reference/prep_lab_data.md) : Prepare lab data - [`racemap`](https://stephenturner.github.io/rpkgdemo/reference/racemap.md) : Race mapping - [`read_labdata()`](https://stephenturner.github.io/rpkgdemo/reference/read_labdata.md) : Read laboratory data - [`rped`](https://stephenturner.github.io/rpkgdemo/reference/rped.md) : RPED: R Package Example Data - [`standardize_race()`](https://stephenturner.github.io/rpkgdemo/reference/standardize_race.md) : Standardize race variable - [`standardize_sex()`](https://stephenturner.github.io/rpkgdemo/reference/standardize_sex.md) : Standardize Sex Variables - [`suppress_counts()`](https://stephenturner.github.io/rpkgdemo/reference/suppress_counts.md) : Suppress Low Counts for Privacy - [`zipcodes`](https://stephenturner.github.io/rpkgdemo/reference/zipcodes.md) : ZIP code data # Articles ### All vignettes - [R Package Development with Positron](https://stephenturner.github.io/rpkgdemo/articles/rpkgdemo.md):