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.
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'
Retrieve all current values
sinew_opts$get()
#> $add_fields
#> [1] "details" "examples" "seealso" "rdname" "export"
#>
#> $cut
#> NULL
#>
#> $pretty_print
#> [1] TRUE
#>
#> $markdown_links
#> [1] FALSE
#>
#> $author
#> [1] "AUTHOR [AUTHOR_2]"
#>
#> $backref
#> [1] "src/filename.cpp"
#>
#> $concept
#> [1] "CONCEPT_TERM_1 [CONCEPT_TERM_2]"
#>
#> $describeIn
#> [1] "FUNCTION_NAME DESCRIPTION"
#>
#> $details
#> [1] "DETAILS"
#>
#> $example
#> [1] "path_to_file/relative/to/packge/root"
#>
#> $examples
#> [1] "\n#' \\dontrun{\n#' if(interactive()){\n#' #EXAMPLE1\n#' }\n#' }"
#>
#> $export
#> [1] ""
#>
#> $family
#> [1] "FAMILY_TITLE"
#>
#> $field
#> [1] "FIELD_IN_S4_RefClass DESCRIPTION"
#>
#> $format
#> [1] "DATA_STRUCTURE"
#>
#> $importClassesFrom
#> [1] "PKG CLASS_a [CLASS_b]"
#>
#> $importMethodsFrom
#> [1] "PKG METHOD_a [METHOD_b]"
#>
#> $include
#> [1] "FILENAME.R [FILENAME_b.R]"
#>
#> $inherit
#> [1] "[PKG::]SOURCE_FUNCTION [FIELD_a FIELD_b]"
#>
#> $inheritDotParams
#> [1] "[PKG::]SOURCE_FUNCTION"
#>
#> $inheritSection
#> [1] "[PKG::]SOURCE_FUNCTION [SECTION_a SECTION_b]"
#>
#> $keywords
#> [1] "KEYWORD_TERM"
#>
#> $name
#> [1] "NAME"
#>
#> $rdname
#> [1] "FUNCTION_NAME"
#>
#> $references
#> [1] "BIB_CITATION"
#>
#> $section
#> [1] "SECTION_NAME"
#>
#> $source
#> [1] "\\url{http://somewhere.important.com/}"
#>
#> $slot
#> [1] "SLOTNAME DESCRIPTION"
#>
#> $template
#> [1] "FILENAME"
#>
#> $templateVar
#> [1] "NAME VALUE"
#>
#> $useDynLib
#> [1] "PKG [ROUTINE_a ROUTINE_b]"
Retrieve a specific field
sinew_opts$get('author')
#> [1] "AUTHOR [AUTHOR_2]"
Retrieve a multiple fields
sinew_opts$get(c('author','source'))
#> $author
#> [1] "AUTHOR [AUTHOR_2]"
#>
#> $source
#> [1] "\\url{http://somewhere.important.com/}"
Set a value
sinew_opts$set(list(author='John Doe'))
sinew_opts$get('author')
#> [1] "John Doe"
Append a new value to the current field values
sinew_opts$get('add_fields')
#> [1] "details" "examples" "seealso" "rdname" "export"
sinew_opts$append(add_fields='source')
sinew_opts$get('add_fields')
#> [1] "details" "examples" "seealso" "rdname" "export" "source"
Reset fields to package defaults
sinew_opts$restore()
sinew_opts$get(c('add_fields','author'))
#> $add_fields
#> [1] "details" "examples" "seealso" "rdname" "export"
#>
#> $author
#> [1] "AUTHOR [AUTHOR_2]"