Learn R Programming

NMOF (version 2.10-0)

showExample: 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)

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.

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)

Author

Enrico Schumann

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.

References

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

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

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

Examples

Run this code
## 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)

Run the code above in your browser using DataLab