Lesson | R Documentation |
This is a wrapper for several Episode class objects.
This class contains and keeps track of relationships between Episode objects contained within Carpentries Workbench and Carpentries styles lessons.
Read more about how to use this class in vignette("intro-lesson", package = "pegboard")
path
[character
] path to Lesson directory
episodes
[list
] list of Episode class objects representing
the episodes of the lesson.
built
[list
] list of Episode class objects representing
the markdown artefacts rendered from RMarkdown files.
extra
[list
] list of Episode class objects representing
the extra markdown components including index, setup, information
for learners, information for instructors, and learner profiles. This
is not processed for the jekyll lessons.
children
[list
] list of Episode class objects representing
child files that are needed by any of the components to be built
This is not processed for the jekyll lessons.
sandpaper
[logical
] when TRUE
, the episodes in the lesson
are written in pandoc flavoured markdown. FALSE
would indicate a
jekyll-based lesson written in kramdown.
rmd
[logical
] when TRUE
, the episodes represent RMarkdown
files, default is FALSE
for markdown files (deprecated and unused).
overview
[logical
] when TRUE
, the lesson is an overview
lesson and does not necessarly contain any episodes. Defaults to FALSE
n_problems
number of problems per episode
show_problems
contents of the problems per episode
files
the source files for each episode
has_children
a logical indicating the presence (TRUE
) or
absence (FALSE
) of child files within the main files of the lesson
new()
create a new Lesson object from a directory
Lesson$new(path = ".", rmd = FALSE, jekyll = TRUE, ...)
path
[character
] path to a lesson directory. This must have a
folder called _episodes
within that contains markdown episodes.
Defaults to the current working directory.
rmd
[logical
] when TRUE
, the imported files will be the
source RMarkdown files. Defaults to FALSE
, which reads the rendered
markdown files.
jekyll
[logical
] when TRUE
(default), the structure of the
lesson is assumed to be derived from the carpentries/styles repository.
When FALSE
, The structure is assumed to be a sandpaper lesson and
extra content for learners, instructors, and profiles will be populated.
...
arguments passed on to Episode$new
a new Lesson object that contains a list of Episode objects in
$episodes
frg <- Lesson$new(lesson_fragment()) frg$path frg$episodes
load_built()
read in the markdown content generated from RMarkdown sources and load load them into memory
Lesson$load_built()
get()
A getter for various active bindings in the Episode class of objects.
In practice this is syntactic sugar around
purrr::map(l$episodes, ~.x$element)
Lesson$get(element = NULL, collection = "episodes")
element
[character
] a defined element from the active bindings
in the Episode class. Defaults to NULL, which will return nothing.
Elements that do not exist in the Episode class will return NULL
collection
[character
] one or more of "episodes" (default),
"extra", or "built". Select TRUE
to collect information from all files.
frg <- Lesson$new(lesson_fragment()) frg$get("error") # error code blocks frg$get("links") # links
summary()
summary of element counts in each episode. This can be useful for assessing a broad overview of the lesson dynamics
Lesson$summary(collection = "episodes")
collection
[character
] one or more of "episodes" (default),
"extra", or "built". Select TRUE
to collect information from all files.
frg <- Lesson$new(lesson_fragment()) frg$summary() # episode summary (default)
blocks()
Gather all of the blocks from the lesson in a list of xml_nodeset objects
Lesson$blocks(type = NULL, level = 0, path = FALSE)
type
the type of block quote in the Jekyll syntax like ".challenge", ".discussion", or ".solution"
level
the level of the block within the document. Defaults to 0
,
which represents all of the block_quotes within the document regardless
of nesting level.
path
[logical
] if TRUE
, the names of each element
will be equivalent to the path. The default is FALSE
, which gives the
name of each episode.
body
the XML body of a carpentries lesson (an xml2 object)
challenges()
Gather all of the challenges from the lesson in a list of xml_nodeset objects
Lesson$challenges(path = FALSE, graph = FALSE, recurse = TRUE)
path
[logical
] if TRUE
, the names of each element
will be equivalent to the path. The default is FALSE
, which gives the
name of each episode.
graph
[logical
] if TRUE
, the output will be a data frame
representing the directed graph of elements within the challenges. See
the get_challenge_graph()
method in Episode.
recurse
[logical
] when graph = TRUE
, this will include the
solutions in the output. See Episode for more details.
solutions()
Gather all of the solutions from the lesson in a list of xml_nodeset objects
Lesson$solutions(path = FALSE)
path
[logical
] if TRUE
, the names of each element
will be equivalent to the path. The default is FALSE
, which gives the
name of each episode.
thin()
Remove episodes that have no challenges
Lesson$thin(verbose = TRUE)
verbose
[logical
] if TRUE
(default), the names of each
episode removed is reported. Set to FALSE
to remove this behavior.
the Lesson object, invisibly
frg <- Lesson$new(lesson_fragment()) frg$thin()
reset()
Re-read all Episodes from disk
Lesson$reset()
the Lesson object
frg <- Lesson$new(lesson_fragment()) frg$episodes[[1]]$body frg$isolate_blocks()$episodes[[1]]$body # empty frg$reset()$episodes[[1]]$body # reset
isolate_blocks()
Remove all elements except for those within block quotes that have a kramdown tag. Note that this is a destructive process.
Lesson$isolate_blocks()
the Episode object, invisibly
frg <- Lesson$new(lesson_fragment()) frg$isolate_blocks()$body # only one challenge block_quote
handout()
create a handout for all episodes in the lesson
Lesson$handout(path = NULL, solution = FALSE)
path
the path to the R Markdown file to be written. If NULL
(default), no file will be written and the lines of the output document
will be returned.
solution
if TRUE
solutions will be retained. Defaults to FALSE
if path = NULL
, a character vector, otherwise, the object
itself is returned.
lsn <- Lesson$new(lesson_fragment("sandpaper-fragment"), jekyll = FALSE) cat(lsn$handout()) cat(lsn$handout(solution = TRUE))
validate_headings()
Validate that the heading elements meet minimum accessibility
requirements. See the internal validate_headings()
for deails.
This will validate the following aspects of all headings:
first heading starts at level 2 (first_heading_is_second_level
)
greater than level 1 (greater_than_first_level
)
increse sequentially (e.g. no jumps from 2 to 4) (are_sequential
)
have names (have_names
)
unique in their own hierarchy (are_unique
)
Lesson$validate_headings(verbose = TRUE)
verbose
if TRUE
, the heading tree will be printed to the console
with any warnings assocated with the validators
a data frame with a variable number of rows and the follwoing columns:
episode the filename of the episode
heading the text from a heading
level the heading level
pos the position of the heading in the document
node the XML node that represents the heading
(the next five columns are the tests listed above)
path the path to the file.
Each row in the data frame represents an individual heading across the
Lesson. See validate_headings()
for more details.
frg <- Lesson$new(lesson_fragment()) frg$validate_headings()
validate_divs()
Validate that the divs are known. See the internal validate_divs()
for
details.
divs are known (is_known
)
Lesson$validate_divs()
verbose
if TRUE
(default), Any failed tests will be printed to
the console as a message giving information of where in the document
the failing divs appear.
a wide data frame with five rows and the number of columns equal to the number of episodes in the lesson with an extra column indicating the type of validation. See the same method in the Episode class for details.
frg <- Lesson$new(lesson_fragment()) frg$validate_divs()
validate_links()
Validate that the links and images are valid and accessible. See the
internal validate_links()
for details.
External links use HTTPS (enforce_https
)
Internal links exist (internal_okay
)
External links are reachable (all_reachable
) (planned)
Images have alt text (img_alt_text
)
Link text is descriptive (descriptive
)
Link text is more than a single letter (link_length
)
Lesson$validate_links()
verbose
if TRUE
(default), Any failed tests will be printed to
the console as a message giving information of where in the document
the failing links/images appear.
a wide data frame with five rows and the number of columns equal to the number of episodes in the lesson with an extra column indicating the type of validation. See the same method in the Episode class for details.
frg <- Lesson$new(lesson_fragment()) frg$validate_links()
trace_lineage()
find all the children of a single source file
Lesson$trace_lineage(episode_path)
episode_path
the path to an episode or extra file
a character vector of the full lineage of files starting with a single source file. Note: this assumes a sandpaper lesson that has child files. If there are no child files, it will return the path
frag <- lesson_fragment("sandpaper-fragment-with-child") lsn <- Lesson$new(frag, jekyll = FALSE) lsn$has_children # TRUE lsn$episodes[[1]]$children # first episode shows 1 immediate child lsn$trace_lineage(lsn$files[[1]]) # find recursive children of 1st episode
clone()
The objects of this class are cloneable with this method.
Lesson$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------
## Method `Lesson$new`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$path
frg$episodes
## ------------------------------------------------
## Method `Lesson$get`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$get("error") # error code blocks
frg$get("links") # links
## ------------------------------------------------
## Method `Lesson$summary`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$summary() # episode summary (default)
## ------------------------------------------------
## Method `Lesson$thin`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$thin()
## ------------------------------------------------
## Method `Lesson$reset`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$episodes[[1]]$body
frg$isolate_blocks()$episodes[[1]]$body # empty
frg$reset()$episodes[[1]]$body # reset
## ------------------------------------------------
## Method `Lesson$isolate_blocks`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$isolate_blocks()$body # only one challenge block_quote
## ------------------------------------------------
## Method `Lesson$handout`
## ------------------------------------------------
lsn <- Lesson$new(lesson_fragment("sandpaper-fragment"), jekyll = FALSE)
cat(lsn$handout())
cat(lsn$handout(solution = TRUE))
## ------------------------------------------------
## Method `Lesson$validate_headings`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$validate_headings()
## ------------------------------------------------
## Method `Lesson$validate_divs`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$validate_divs()
## ------------------------------------------------
## Method `Lesson$validate_links`
## ------------------------------------------------
frg <- Lesson$new(lesson_fragment())
frg$validate_links()
## ------------------------------------------------
## Method `Lesson$trace_lineage`
## ------------------------------------------------
frag <- lesson_fragment("sandpaper-fragment-with-child")
lsn <- Lesson$new(frag, jekyll = FALSE)
lsn$has_children # TRUE
lsn$episodes[[1]]$children # first episode shows 1 immediate child
lsn$trace_lineage(lsn$files[[1]]) # find recursive children of 1st episode
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.