yspec.RmdThe yspec package will read you data specification file when it is written in a specific yaml format.
For each data set in your project that needs documentation, create a yaml file that lists the columns in the data set along with details about the data in that column. This yaml file can be loaded into your R session into an object that you can work with. This is referred to as a spec object. The term spec refers to a single documented data object / data file.
Once all of your data sets have been documented with their own yaml file, you can create another object called a yproj objects. This is used to template the rendering of a single integrated data definitions file for your entire project.
Keep reading the vignette to see how it works.
library(yspec)
An example specification file looks like:
SETUP__:
description: Example PopPK analysis data set.
sponsor: example-project
projectnumber: examp101F
use_internal_db: true
glue:
mugL: "$\\mu$g/L"
C:
NUM:
ID:
SUBJ: !look
TIME:
label: time after first dose
unit: hour
SEQ:
label: data type
values: {observation: 0, dose: 1}
CMT:
EVID:
make_factor: true
lookup: true
AMT: !look
unit: mg
DV: !look
unit: "<<mugL>>"
AGE:
WT:
CRCL:
label: creatinine clearance
Once the data specification yaml file is written, it can be loaded in R
spec <- ys_load(specfile) spec
name c d unit short source
C + + . comment character ysdb_internal.yml
NUM - - . record number ysdb_internal.yml
ID - - . subject identifier ysdb_internal.yml
SUBJ + - . subject identifier ysdb_internal.yml
TIME - - hour TIME .
SEQ - + . SEQ .
CMT - - . compartment number ysdb_internal.yml
EVID - - . event ID ysdb_internal.yml
AMT - - mg dose amount ysdb_internal.yml
DV - - <<mugL>> dependent variable ysdb_internal.yml
AGE - - years age ysdb_internal.yml
WT - - kg weight ysdb_internal.yml
CRCL - - ml/min CRCL .
ALB - - g/dL albumin ysdb_internal.yml
BMI - - m2/kg BMI ysdb_internal.yml
AAG - - mg/dL alpha-1-acid glycoprotein .
SCR - - mg/dL serum creatinine .
AST - - . aspartate aminotransferase .
ALT - - . alanine aminotransferase .
HT - - cm height ysdb_internal.yml
CP - + . Child-Pugh score .
TAFD - - hours time after first dose .
TAD - - hours time after dose .
LDOS - - mg last dose amount .
MDV - - . MDV ysdb_internal.yml
BLQ - + . below limit of quantification .
PHASE - - . study phase indicator .
STUDY - + . study number .
RF + + . renal function stage .
Data from specific columns can be printed
spec$WT
name value
col WT
type numeric
short weight
unit kg
range .
or summarized
summary(spec, WT, DV, EGFR)
name c d unit short source
1 C + + . comment character ysdb_internal.yml
2 NUM - - . record number ysdb_internal.yml
3 ID - - . subject identifier ysdb_internal.yml
4 SUBJ + - . subject identifier ysdb_internal.yml
5 TIME - - hour TIME .
6 SEQ - + . SEQ .
7 CMT - - . compartment number ysdb_internal.yml
8 EVID - - . event ID ysdb_internal.yml
9 AMT - - mg dose amount ysdb_internal.yml
10 DV - - <<mugL>> dependent variable ysdb_internal.yml
11 AGE - - years age ysdb_internal.yml
12 WT - - kg weight ysdb_internal.yml
13 CRCL - - ml/min CRCL .
14 ALB - - g/dL albumin ysdb_internal.yml
15 BMI - - m2/kg BMI ysdb_internal.yml
16 AAG - - mg/dL alpha-1-acid glycoprotein .
17 SCR - - mg/dL serum creatinine .
18 AST - - . aspartate aminotransferase .
19 ALT - - . alanine aminotransferase .
20 HT - - cm height ysdb_internal.yml
21 CP - + . Child-Pugh score .
22 TAFD - - hours time after first dose .
23 TAD - - hours time after dose .
24 LDOS - - mg last dose amount .
25 MDV - - . MDV ysdb_internal.yml
26 BLQ - + . below limit of quantification .
27 PHASE - - . study phase indicator .
28 STUDY - + . study number .
29 RF + + . renal function stage .
Use the ys_check() function, with the data frame as the first argument and the spec object as the second argument
## The data set passed all checks.
The specification object can be rendered to a specification file with the ys_document function
ys_document(spec, stem = "working_document")
## Warning: LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 53.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 56.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 59.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 79.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 102.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 105.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 108.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 128.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 259.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 262.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 265.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 268.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 313.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 316.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 319.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 322.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/it/12'. Switching off
## (microtype) protrusion for this font on input line 77.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/it/8'. Switching off
## (microtype) protrusion for this font on input line 77.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OMS/mdput/m/n/12'. Switching off
## (microtype) protrusion for this font on input line 77.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OMS/mdput/m/n/8'. Switching off
## (microtype) protrusion for this font on input line 77.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/n/12'. Switching off
## (microtype) protrusion for this font on input line 77.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/n/8'. Switching off
## (microtype) protrusion for this font on input line 77.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/it/10'. Switching off
## (microtype) protrusion for this font on input line 117.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OMS/mdput/m/n/10'. Switching off
## (microtype) protrusion for this font on input line 117.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/n/10'. Switching off
## (microtype) protrusion for this font on input line 117.
With output here.
ys_document will pass along arguments to rmarkdown::render so that you can control those aspects of how the document is rendered. You can also create custom output formats to get the data table to render in the way that you like.
To create an project-wide listing of documented data sets, we create a yproj or project object. We create this from the spec objects that we read about in the previous section. Let’s load another object to use along with the object loaded in the previous section.
pdspec <- load_spec_ex("DEM104101F_PKPD.yml")
Now, we have two objects to work with:
head(spec)
## name c d unit short source
## 1 C + + . comment character ysdb_internal.yml
## 2 NUM - - . record number ysdb_internal.yml
## 3 ID - - . subject identifier ysdb_internal.yml
## 4 SUBJ + - . subject identifier ysdb_internal.yml
## 5 TIME - - hour TIME .
## 6 SEQ - + . SEQ .
## 7 CMT - - . compartment number ysdb_internal.yml
## 8 EVID - - . event ID ysdb_internal.yml
## 9 AMT - - mg dose amount ysdb_internal.yml
## 10 DV - - <<mugL>> dependent variable ysdb_internal.yml
head(pdspec)
## name c d unit short source
## 1 C + - . C .
## 2 MDV - - . MDV .
## 3 SEQ - + . SEQ .
## 4 AMT - - mg AMT .
## 5 II - - hours II .
## 6 CMT - - . Compartment .
## 7 TAFD - - hours TAFD .
## 8 WT - - kg Weight .
## 9 EGFR - - ml/min/1.73 m2 eGFR .
## 10 SEX - + . SEX .
We can create a project object from both objects
proj <- ys_project(spec,pdspec) proj
## projectnumber: examp101F
## sponsor: example-project
## --------------------------------------------
## datafiles:
## name description data_stem
## analysis1 Example PopPK analysis data set. analysis1
## DEM104101F_PKPD Population PKPD analysis data set DEM104101F_PKPD
To render the project file we’ll use the same ys_document() function.
This time, we’ll add some extra (optional) arguments that will help us get the document to look the way we want:
ys_document( proj, stem = "project_document", build_dir = mrgtemplate(), author = "Michelle Johnson", title = "Analysis data specification" )
## Warning: LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 53.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 56.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 59.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 79.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 102.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 105.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 108.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 128.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 259.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 262.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 265.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 268.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 313.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 316.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 319.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 322.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/it/10'. Switching off
## (microtype) protrusion for this font on input line 233.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OMS/mdput/m/n/10'. Switching off
## (microtype) protrusion for this font on input line 233.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/n/10'. Switching off
## (microtype) protrusion for this font on input line 233.
With output here.
Using the build_dir argument gets us the document rendered with Metrum Research Group branding. Also, author and title are passed into the configuration fields for this document.
To get a document that is formatted according to FDA requirements, use:
ys_document( proj, type = "regulatory", stem = "fda_document", build_dir = mrgtemplate(), author = "Michelle Johnson", title = "Analysis data specification" )
## Warning: LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 53.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 56.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 59.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 79.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 102.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 105.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 108.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 128.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 259.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 262.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 265.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 268.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 313.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 316.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 319.
## LaTeX Warning: Font shape declaration has incorrect series value `mc'.
## It should not contain an `m'! Please correct it.
## Found on input line 322.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/it/10'. Switching off
## (microtype) protrusion for this font on input line 236.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OMS/mdput/m/n/10'. Switching off
## (microtype) protrusion for this font on input line 236.
## Package microtype Warning: I cannot find a protrusion list for font
## (microtype) `OML/mdput/m/n/10'. Switching off
## (microtype) protrusion for this font on input line 236.
With output here.