metrumresearchgroup / yspec

Data Specification for Pharmacometrics
https://metrumresearchgroup.github.io/yspec
5 stars 2 forks source link

Customize short name #13

Closed kylebaron closed 4 years ago

kylebaron commented 4 years ago

Summary

Tests

kylebaron commented 4 years ago
library(yspec)
library(tidyverse)

sp <- ys_help$spec()

Get the short name

ys_get_short(sp)[1:15]
#> $C
#> [1] "comment character"
#> 
#> $NUM
#> [1] "record number"
#> 
#> $ID
#> [1] "subject identifier"
#> 
#> $SUBJ
#> [1] "subject identifier"
#> 
#> $TIME
#> [1] "TIME"
#> 
#> $SEQ
#> [1] "SEQ"
#> 
#> $CMT
#> [1] "compartment number"
#> 
#> $EVID
#> [1] "event ID"
#> 
#> $AMT
#> [1] "dose amount"
#> 
#> $DV
#> [1] "dependent variable"
#> 
#> $AGE
#> [1] "age"
#> 
#> $WT
#> [1] "weight"
#> 
#> $CRCL
#> [1] "CRCL"
#> 
#> $ALB
#> [1] "albumin"
#> 
#> $BMI
#> [1] "BMI"

Convert to title case

ys_get_short(sp, title_case=TRUE)[10:15]
#> $DV
#> [1] "Dependent Variable"
#> 
#> $AGE
#> [1] "Age"
#> 
#> $WT
#> [1] "Weight"
#> 
#> $CRCL
#> [1] "CRCL"
#> 
#> $ALB
#> [1] "Albumin"
#> 
#> $BMI
#> [1] "BMI"

Revert to col name when short is too long

ys_get_short(sp, short_max = 7)[10:15]
#> $DV
#> [1] "DV"
#> 
#> $AGE
#> [1] "age"
#> 
#> $WT
#> [1] "weight"
#> 
#> $CRCL
#> [1] "CRCL"
#> 
#> $ALB
#> [1] "albumin"
#> 
#> $BMI
#> [1] "BMI"

Form col labels

axis_col_labs(sp, vars(SCR, AGE, WT, CRCL, ALB, BMI), title_case=TRUE)
#>                             SCR                             AGE 
#> "SCR//Serum Creatinine (mg/dL)"              "AGE//Age (years)" 
#>                              WT                            CRCL 
#>               "WT//Weight (kg)"           "CRCL//CRCL (ml/min)" 
#>                             ALB                             BMI 
#>           "ALB//Albumin (g/dL)"              "BMI//BMI (m2/kg)"

Also

ys_get_short_unit(sp, parens=TRUE)[11:15]
#> $AGE
#> [1] "age (years)"
#> 
#> $WT
#> [1] "weight (kg)"
#> 
#> $CRCL
#> [1] "CRCL (ml/min)"
#> 
#> $ALB
#> [1] "albumin (g/dL)"
#> 
#> $BMI
#> [1] "BMI (m2/kg)"

Created on 2020-07-02 by the reprex package (v0.3.0)

kylebaron commented 4 years ago

Example with pmplots

library(tidyverse)
library(pmplots)
library(yspec)

data <- pmplots_data_id()

spec <- ys_help$spec()

data <- ys_add_factors(data,spec)

cols <- axis_col_labs(spec, vars(WT,ALB,SCR,AAG), title_case=TRUE)

wrap_cont_cat(data, x = "RF_f", y = cols, use_labels=TRUE) +
  xlab("Renal Function Category")

Created on 2020-07-02 by the reprex package (v0.3.0)