Session Options

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(sinew)

sinew options can be set to remain persistent across sessions or at a global level within a session

For those familiar with knitr sinew follows the same option logic, and instead of knitr::opts_chunk we define sinew::sinew_opts.

The defaults settings for the core function parameters in sinew are defined in sinew_opts. These include the roxygen2 fields and their values to include by default in the function header.

These settings will persist for a R session.

If the user needs the settings to persist across sessions, like in package development, sinew reads on load a file called _sinewconfig.yml, placed in the working directory.

Using _sinewconfig.yml

When loading the sinew package the file _sinewconfig.yml will be searched for in the working directory, if found settings found in it will be used instead of the package defaults.

To create the _sinewconfig.yml file in the current project directory and update the .Rbuildignore automatically use the function create_yml(). In the example below the field author will be added to all roxygen2 headers returned by sinew and its value is Jonathan Sidi.

add_fields: ["author"]
author: 'Jonathan Sidi'

Using sinew_opts

Retrieve all current values

sinew_opts$get()

Retrieve a specific field

sinew_opts$get('author')

Retrieve a multiple fields

sinew_opts$get(c('author','source'))

Set a value

sinew_opts$set(list(author='John Doe'))
sinew_opts$get('author')

Append a new value to the current field values

sinew_opts$get('add_fields')
sinew_opts$append(add_fields='source')
sinew_opts$get('add_fields')

Reset fields to package defaults

sinew_opts$restore()
sinew_opts$get(c('add_fields','author'))


Try the sinew package in your browser

Any scripts or data that you put into this service are public.

sinew documentation built on March 31, 2022, 5:06 p.m.