get_fm: Get front-matter values

View source: R/get_fm.R

get_fmR Documentation

Get front-matter values

Description

Imports meta/front-matter.yml value(s) to environment as a list.

Usage

get_fm(
  key = NULL,
  WD = "?",
  WD_git = NULL,
  yaml_path = NULL,
  checkWD = FALSE,
  auto_init = FALSE,
  check = NULL,
  always_list = FALSE,
  standardize_NA = TRUE,
  ...
)

Arguments

key

which entry (or entries) do you want to import? default=NULL will import everything; Supports "starts with", case-insensitive matching for a single key if prefixed with '~'

WD

working directory; default=getwd(); if "?" supplied, will invoke pick_lesson(). The basename of this working directory will then be used to find a match in the gp-lessons git project folder by calling get_wd_git(). It's a little roundabout, but is consistent with lookups centering on the Google Drive project working directory.

WD_git

default=NULL. If you already know the path to the gp-lessons folder, this is more efficient.

yaml_path

default=NULL. An alternate way to just provide a full path to read in a yml file.

checkWD

passed to safe_read_yaml(); default=FALSE; set to FALSE to suppress warnings if for example you're missing teach-it.gsheet or some other item expected to be in a lesson directory

auto_init

logical; do you want to automatically create a front-matter.yml file if it's not found? Runs init_fm(); default=FALSE

check

string referring to a check function(x) to pass to checkmate::assert(); e.g. check="checkmate::check_character(x,min.chars=10)" will throw an error if an output is not a string of at least 10 characters. default=NULL

always_list

logical; do you want to always return a list? default=FALSE will unlist() the result if it seems to be a single item

standardize_NA

logical; do you want all "",NULL,list(), etc. to be read in as NA using is_empty()? passed to safe_read_yaml(); default=TRUE

...

additional args passed to check function

Details

If you ask for only one key, output will be a vector, rather than a list

Value

Tries to cromulently return an appropriate string, tibble, list or vector of values for the associated keys.

Examples

get_fm()
get_fm(key=c("Title","ShortTitle","locale"))
get_fm(key="Title",WD=pick_lesson())
#partial matching for all front-matter entries starting with 'gdrive' (case insensitive)
get_fm("gdrive","?")

galacticpolymath/GPpub documentation built on April 5, 2025, 6:04 p.m.