A storage cache for pegboard::Lesson objects and other pre-computed items for use by other internal functions while sandpaper is working.
Usage
this_lesson(path)
clear_this_lesson()
set_this_lesson(path)
set_resource_list(path)
clear_resource_list(path)
Lesson Object Storage
this_lesson()
will return a pegboard::Lesson object if it has
previously been stored. There are three values that are cached:
.this_lesson
a pegboard::Lesson object.this_diff
a charcter vector fromgert::git_diff_patch()
.this_status
a data frame fromgert::git_status()
.this_commit
the hash of the most recent commit
The function this_lesson()
first checks if .this_diff
is different than
the output of gert::git_diff_patch()
, then checks if there are any
changes to gert::git_status()
, and then finally checks if the commits are
identical. If there are differences or the values are not previously
cached, the lesson is loaded into memory, otherwise, it is fetched from the
previously stored lesson.
The storage cache is in a global package object called .store
, which is
initialised when sandpaper is loaded via .lesson_store()
If there have been no changes git is aware of, the lesson remains the same.
Pre-Computed Object Storage
A side-effect of this_lesson()
is that it will also initialise
pre-computed objects that pertain to the lesson itself. These are
initialised via set_globals()
. These storage objects are:
.resources
: a list of markdown resources for the lesson derived fromget_resource_list()
viaset_resource_list()
this_metadata
: metadata with template for including in the pages. initialised ininitialise_metadata()
viaset_globals()
learner_globals
: variables for the learner version of the pages initialised inset_globals()
instructor_globals
: variables for the instructor version of the pages initialised inset_globals()
Examples
tmp <- tempfile()
create_lesson(tmp, open = FALSE)
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> ℹ No schedule set, using Rmd files in episodes/ directory.
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> → To remove this message, define your schedule in config.yaml or use `set_episodes()` to generate it.
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> ────────────────────────────────────────────────────────────────────────
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> ℹ To save this configuration, use
#>
#> set_episodes(path = path, order = ep, write = TRUE)
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> ✔ First episode created in /tmp/RtmpP9eYUD/file19326559eae5/episodes/introduction.Rmd
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> ℹ Workflows up-to-date!
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> ℹ Consent to use package cache provided
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> - The project is out-of-sync -- use `renv::status()` for details.
#> → Searching for and installing available dependencies
#> The following packages were discovered:
#>
#> # ~/work/_temp/Library -------------------------------------------------------
#> - R6 2.5.1
#> - base64enc 0.1-3
#> - bslib 0.7.0
#> - cachem 1.1.0
#> - cli 3.6.3
#> - digest 0.6.36
#> - evaluate 0.24.0
#> - fastmap 1.2.0
#> - fontawesome 0.5.2
#> - fs 1.6.4
#> - glue 1.7.0
#> - highr 0.11
#> - htmltools 0.5.8.1
#> - jquerylib 0.1.4
#> - jsonlite 1.8.8
#> - knitr 1.48
#> - lifecycle 1.0.4
#> - memoise 2.0.1
#> - mime 0.12
#> - rappdirs 0.3.3
#> - rlang 1.1.4
#> - rmarkdown 2.27
#> - sass 0.4.9
#> - tinytex 0.52
#> - xfun 0.46
#> - yaml 2.3.10
#>
#> They will be copied into the project library.
#>
#> - Copying packages into the project library ... Done!
#> - Hydrated 26 packages in 0.21 seconds.
#> - Resolving missing dependencies ...
#> # Installing packages --------------------------------------------------------
#> - The project is out-of-sync -- use `renv::status()` for details.
#> → Recording changes in lockfile
#> The following package(s) will be updated in the lockfile:
#>
#> # GitHub ---------------------------------------------------------------------
#> - renv [* -> rstudio/renv]
#>
#> # https://packagemanager.posit.co/cran/__linux__/jammy/latest ----------------
#> - R6 [* -> 2.5.1]
#> - base64enc [* -> 0.1-3]
#> - bslib [* -> 0.7.0]
#> - cachem [* -> 1.1.0]
#> - cli [* -> 3.6.3]
#> - digest [* -> 0.6.36]
#> - evaluate [* -> 0.24.0]
#> - fastmap [* -> 1.2.0]
#> - fontawesome [* -> 0.5.2]
#> - fs [* -> 1.6.4]
#> - glue [* -> 1.7.0]
#> - highr [* -> 0.11]
#> - htmltools [* -> 0.5.8.1]
#> - jquerylib [* -> 0.1.4]
#> - jsonlite [* -> 1.8.8]
#> - knitr [* -> 1.48]
#> - lifecycle [* -> 1.0.4]
#> - memoise [* -> 2.0.1]
#> - mime [* -> 0.12]
#> - rappdirs [* -> 0.3.3]
#> - rlang [* -> 1.1.4]
#> - rmarkdown [* -> 2.27]
#> - sass [* -> 0.4.9]
#> - tinytex [* -> 0.52]
#> - xfun [* -> 0.46]
#> - yaml [* -> 2.3.10]
#>
#> The version of R recorded in the lockfile will be updated:
#> - R [* -> 4.4.1]
#>
#> - Lockfile written to "/tmp/RtmpP9eYUD/file19326559eae5/renv/profiles/lesson-requirements/renv.lock".
#> ✔ Lesson successfully created in /tmp/RtmpP9eYUD/file19326559eae5
#> → Creating Lesson in /tmp/RtmpP9eYUD/file19326559eae5...
#> /tmp/RtmpP9eYUD/file19326559eae5
# Read the lesson into cache
system.time(sandpaper:::this_lesson(tmp))
#> user system elapsed
#> 0.104 0.016 0.120
system.time(sandpaper:::this_lesson(tmp)) # less time to read in once cached
#> user system elapsed
#> 0.004 0.000 0.004
l <- sandpaper:::this_lesson(tmp)
l
#> <Lesson>
#> Public:
#> blocks: function (type = NULL, level = 0, path = FALSE)
#> built: NULL
#> challenges: function (path = FALSE, graph = FALSE, recurse = TRUE)
#> children: NULL
#> clone: function (deep = FALSE)
#> episodes: list
#> extra: list
#> files: active binding
#> get: function (element = NULL, collection = "episodes")
#> handout: function (path = NULL, solution = FALSE)
#> has_children: active binding
#> initialize: function (path = ".", rmd = FALSE, jekyll = TRUE, ...)
#> isolate_blocks: function ()
#> load_built: function ()
#> n_problems: active binding
#> overview: FALSE
#> path: /tmp/RtmpP9eYUD/file19326559eae5
#> reset: function ()
#> rmd: FALSE
#> sandpaper: TRUE
#> show_problems: active binding
#> solutions: function (path = FALSE)
#> summary: function (collection = "episodes")
#> thin: function (verbose = TRUE)
#> trace_lineage: function (episode_path)
#> validate_divs: function ()
#> validate_headings: function (verbose = TRUE)
#> validate_links: function ()
#> Private:
#> deep_clone: function (name, value)
# clear the cache
sandpaper:::clear_this_lesson()
system.time(sandpaper:::this_lesson(tmp)) # have to re-read the lesson
#> user system elapsed
#> 0.113 0.000 0.113
system.time(sandpaper:::this_lesson(tmp))
#> user system elapsed
#> 0.005 0.000 0.005
unlink(tmp)