rpruim / fastR2

Foundations and Applications of Statistics: An Introduction Using R
13 stars 10 forks source link

Example 2.2.3: "binom.R" not found by snippet #10

Closed homerhanumat closed 6 years ago

homerhanumat commented 6 years ago

snippet("binom") runs several snippets containing the string "binom", eventually throwing an error at binom-grid.R, but never runs binom.R.

Current workaround is snippet("^binom\\.R$") .

rpruim commented 6 years ago

I've reworked how snippet() finds things. It now uses partial string matching against an internal list of chunk names as is aware of sequences of snippets. When there are multiple matches, they are listed to help the user refine the request.

library(fastR2)

# Multiple partial matches are displayed
snippet("bin", execute = FALSE, view = FALSE)
#> Multiple matches found for `bin': 
#>   binom, binom-bayes, binom-cis, binom-grid, binom-lci, binom-odds-ci, binom-wald-ci, binomial-ztest

# Exact match is used
snippet("binom", execute = FALSE, view = FALSE)
#> 
#> ## snippet: binom

# snippet() is aware of sequential numbering
snippet("binom-b", execute = FALSE, view = FALSE)
#> 
#> ## snippet: binom-bayes01
#> 
#> ## snippet: binom-bayes02

# To get one chunk from a sequence, use the full name
snippet("binom-bayes01", execute = FALSE, view = FALSE)
#> 
#> ## snippet: binom-bayes01

Created on 2018-08-14 by the reprex package (v0.2.0).