About

The yspec package will read your data specification file when it is written in a specific yaml format. Using the object created from this file, you can validate data assembly outputs, label the data frame to be written in sas xport format, create a define.pdf document, and more.

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)

Example spec file

An example specification file looks like:

specfile <- ys_help$file()

cat(readLines(specfile)[1:29], sep = "\n")

Once the data specification yaml file is written, it can be loaded in R

spec <- ys_load(specfile)

spec

Data from specific columns can be printed

spec$WT

or summarized

summary(spec, WT, DV, EGFR)

Items that you should be including for most columns

Check a data set against the spec

Use the ys_check() function, with the data frame as the first argument and the spec object as the second argument

data <- ys_help$data()

ys_check(data, spec)

Example to render spec

The specification object can be rendered to a specification file with the ys_document function

ys_document(spec, stem = "working_document")

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.

Example project object

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)

head(pdspec)

We can create a project object from both objects

proj <- ys_project(spec,pdspec)

proj

Render a project file

Working document

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 = definetemplate(),
  author = "Michelle Johnson", 
  title = "Analysis data specification"
)

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.

Regulatory document

To get a document that is formatted according to FDA requirements, use:

ys_document(
  proj, 
  type = "regulatory",
  stem = "fda_document", 
  build_dir = definetemplate(),
  author = "Michelle Johnson", 
  title = "Analysis data specification"
)


metrumresearchgroup/yspec documentation built on May 24, 2024, 12:48 a.m.