This vignette shows you how to extract information from a yspec object.
knitr::opts_chunk$set(comment = '.')
library(purrr) library(dplyr) library(yspec)
First, recall that the yspec object is just a list. We can use map to get
information out of that list. For example, to find the types of all the columns
in the data set use purrr:::map
spec <- ys_help$spec() map(spec, "type")[1:5]
If we wanted some column information in csv format we could also do
map(spec, ~ paste(.x[["col"]],.x[["short"]],.x[["type"]],sep=','))[1:3]
There are other helper functions that do more than just pull a field. We can extract a label and form a unit.
Call ys_get_unit
to get a named list of units. When the parens
argument is
true, it will put parentheses around the unit. Notice that the output here is
different than if we were to only map across the list and ask for the unit field.
Many columns don't have units and we'd get NULL
back if we just mapped. The
ys_get_unit
function subs in blank character data items when unit
is NULL
.
ys_get_unit(spec, parens = TRUE) %>% unlist()
We can also get labels
ys_get_label(spec)[1:3]
We can also get the short name
ys_get_short(spec)[1:3]
This function returns a string with both the unit
and short
ys_get_short_unit(spec, parens = TRUE)[1:5] %>% as.list
The information you entered in SETUP__
as well as other meta information is
stored as a list in the meta
attribute of the yspec
list. It can be
accessed with get_meta
. This returns a list with the various pieces of meta
data.
get_meta(spec)[1:3]
You an pull a single piece of meta data with
pull_meta(spec, "projectnumber")
m <- get_meta(spec)
names(m)
Some descriptions:
spec_file
: the yaml source file for the specification informationspec_path
: the directory where the yaml source file is locatedname
: the stem of the yaml source filedata_stem
: the stem that is used and it is assumed that data sets will be
written using this stem (for example <data_stem>.csv
etc).data_path
: the assumed derived data directorySee also reference.html for descriptions of meta fields.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.