showExample {NMOF}R Documentation

Display Code Examples

Description

Display the code examples from ‘Numerical Methods and Optimization and Finance’.

Usage

showExample(file = "", chapter = NULL, showfile = TRUE,
            includepaths = FALSE, edition = 2, search,
            ..., ignore.case = TRUE)
showChapterNames(edition = 2)

Arguments

file

a character vector of length one. See Details.

chapter

optional: a character vector of length one, giving the chapter name (see Details), or an integer, indicating a chapter number. Default is NULL: look in all chapters.

showfile

Should the file be displayed with file.show? Defaults to TRUE. A file will be displayed only if one single file only is identified by file and chapter.

includepaths

Should the file paths be displayed? Defaults to FALSE.

...

Arguments passed to grepl; see Details.

edition

an integer: 1 and 2 are supported

search

a regular expression: search in the code files. Not supported yet.

ignore.case

passed to grepl; see Examples. Default is TRUE (which is much more helpful than the default FALSE before package version 2)

Details

showExample matches the specified file argument against the available file names via grepl(file, all.filenames, ignore.case = ignore.case, ...). If chapter is specified, a second match is performed, grepl(chapter, all.chapternames, ignore.case = ignore.case, ...). The chapternames are those in the book (e.g., ‘Modeling dependencies’). The selected files are then those for which file name and chapter name could be matched.

Value

showExample returns a data.frame of at least two character vectors, Chapter and File. If includepaths is TRUE, Paths are included. If no file is found, the data.frame has zero rows. If a single file is identified and showfile is TRUE, the function has the side effect of displaying that file.

showChapterNames returns a character vector: the names of the book's chapters.

Note

The behaviour of the function changed slightly with version 2.0 to accommodate the code examples of the second edition of the book. Specifically, the function gained an argument edition, which defaults to 2. Also, the default for ignore.case was changed to TRUE. To get back the old behaviour of the function, set edition to 1 and ignore.case to FALSE.

The code files can also be downloaded from https://gitlab.com/NMOF .

Author(s)

Enrico Schumann

References

Gilli, M., Maringer, D. and Schumann, E. (2011) Numerical Methods and Optimization in Finance. Elsevier. doi:10.1016/C2009-0-30569-3

Gilli, M., Maringer, D. and Schumann, E. (2019) Numerical Methods and Optimization in Finance. 2nd edition. Elsevier. doi:10.1016/C2017-0-01621-X

Schumann, E. (2023) Financial Optimisation with R (NMOF Manual). http://enricoschumann.net/NMOF.htm#NMOFmanual

Examples

## list all files
showExample()  ## 2nd edition is default
showExample(edition = 1)

## list specific files
showExample("Appendix")
showExample("Backtesting")
showExample("Heuristics")

showExample("tutorial") ## matches against filename
showExample(chapter = 13)
showExample(chapter = "tutorial")

## show where a file is installed
showExample(chapter = "portfolio", includepaths = TRUE)



## first edition
showExample("equations.R", edition = 1)
showExample("example", chapter = "portfolio", edition = 1)

showExample("example", chapter = 13, edition = 1)
showExample("example", chapter = showChapterNames(1)[13L], edition = 1)

[Package NMOF version 2.8-0 Index]