Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lesson Template
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
prace-lessons
Lesson Template
Commits
6bb7b27a
Commit
6bb7b27a
authored
8 years ago
by
Greg Wilson
Browse files
Options
Downloads
Plain Diff
Merging R handling from styles
parents
9304733b
3de94867
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+14
-3
14 additions, 3 deletions
Makefile
bin/chunk-options.R
+16
-6
16 additions, 6 deletions
bin/chunk-options.R
bin/generate_md_episodes.R
+15
-0
15 additions, 0 deletions
bin/generate_md_episodes.R
bin/knit_lessons.sh
+5
-0
5 additions, 0 deletions
bin/knit_lessons.sh
with
50 additions
and
9 deletions
Makefile
+
14
−
3
View file @
6bb7b27a
...
...
@@ -16,11 +16,11 @@ commands :
@
grep
-h
-E
'^##'
${
MAKEFILES
}
|
sed
-e
's/## //g'
## serve : run a local server.
serve
:
serve
:
lesson-rmd
${
JEKYLL
}
serve
--config
_config.yml,_config_dev.yml
## site : build files but do not run a server.
site
:
site
:
lesson-rmd
${
JEKYLL
}
build
--config
_config.yml,_config_dev.yml
## figures : re-generate inclusion displaying all figures.
...
...
@@ -35,6 +35,8 @@ clean :
@
find
.
-name
.DS_Store
-exec
rm
{}
\;
@
find
.
-name
'*~'
-exec
rm
{}
\;
@
find
.
-name
'*.pyc'
-exec
rm
{}
\;
@
rm
-rf
${
RMD_DST
}
@
rm
-rf
fig/swc-rmd-
*
## ----------------------------------------
## Commands specific to workshop websites.
...
...
@@ -48,7 +50,11 @@ workshop-check :
## ----------------------------------------
## Commands specific to lesson websites.
.PHONY
:
lesson-check lesson-files lesson-fixme lesson-single
.PHONY
:
lesson-check lesson-rmd lesson-files lesson-fixme lesson-single
# RMarkdown files
RMD_SRC
=
$(
wildcard _episodes_rmd/??-
*
.Rmd
)
RMD_DST
=
$(
patsubst _episodes_rmd/%.Rmd,_episodes/%.md,
$(
RMD_SRC
))
# Lesson source files in the order they appear in the navigation menu.
SRC_FILES
=
\
...
...
@@ -70,6 +76,10 @@ HTML_FILES = \
$(
patsubst _extras/%.md,
${
DST
}
/%/index.html,
$(
wildcard _extras/
*
.md
))
\
${
DST
}
/license/index.html
## lesson-rmd: : convert Rmarkdown files to markdown
lesson-rmd
:
$(RMD_SRC)
@
bin/knit_lessons.sh
## lesson-check : validate lesson Markdown.
lesson-check
:
@
bin/lesson_check.py
-s
.
-p
${
PARSER
}
...
...
@@ -79,6 +89,7 @@ unittest :
## lesson-files : show expected names of generated files for debugging.
lesson-files
:
@
echo
'RMarkdown:'
${
RMD_SRC
}
@
echo
'source:'
${
SRC_FILES
}
@
echo
'generated:'
${
HTML_FILES
}
...
...
This diff is collapsed.
Click to expand it.
bin/chunk-options.R
+
16
−
6
View file @
6bb7b27a
...
...
@@ -5,27 +5,37 @@
# http://yihui.name/knitr/options#chunk_options
library
(
"knitr"
)
fix_fig_path
<-
function
(
pth
)
file.path
(
".."
,
pth
)
## We use the swc-rmd- prefix for the figures generated by the lssons
## so they can be easily identified and deleted by `make clean`. The
## working directory when the lessons are generated is the root so the
## figures need to be saved in fig/, but when the site is generated,
## the episodes will be one level down. We fix the path using the
## `fig.process` option.
opts_chunk
$
set
(
tidy
=
FALSE
,
results
=
"markup"
,
comment
=
NA
,
fig.align
=
"center"
,
fig.path
=
"fig/"
)
fig.align
=
"center"
,
fig.path
=
"fig/swc-rmd-"
,
fig.process
=
fix_fig_path
)
# The hooks below add html tags to the code chunks and their output so that they
# are properly formatted when the site is built.
hook_in
<-
function
(
x
,
options
)
{
stringr
::
str_c
(
"\n\n~~~{.r}\n"
,
paste0
(
x
,
collapse
=
"\n"
),
"\n~~~\n\n"
)
"\n~~~\n
{: .source}\n
\n"
)
}
hook_out
<-
function
(
x
,
options
)
{
stringr
::
str_c
(
"\n\n~~~
{.output}
\n"
,
stringr
::
str_c
(
"\n\n~~~\n"
,
paste0
(
x
,
collapse
=
"\n"
),
"\n~~~\n\n"
)
"\n~~~\n
{: .output}\n
\n"
)
}
hook_error
<-
function
(
x
,
options
)
{
stringr
::
str_c
(
"\n\n~~~
{.error}
\n"
,
stringr
::
str_c
(
"\n\n~~~\n"
,
paste0
(
x
,
collapse
=
"\n"
),
"\n~~~\n\n"
)
"\n~~~\n
{: .error}\n
\n"
)
}
knit_hooks
$
set
(
source
=
hook_in
,
output
=
hook_out
,
warning
=
hook_error
,
...
...
This diff is collapsed.
Click to expand it.
bin/generate_md_episodes.R
0 → 100644
+
15
−
0
View file @
6bb7b27a
if
(
require
(
"knitr"
))
{
if
(
packageVersion
(
"knitr"
)
<
'1.9.19'
)
{
stop
(
"knitr must be version 1.9.20 or higher"
)
}
}
else
stop
(
"knitr 1.9.20 or above is needed to build the lessons."
)
if
(
!
require
(
"stringr"
))
stop
(
"The package stringr is required for generating the lessons."
)
src_rmd
<-
list.files
(
pattern
=
"??-*.Rmd$"
,
path
=
"_episodes_rmd"
,
full.names
=
TRUE
)
dest_md
<-
file.path
(
"_episodes"
,
gsub
(
"Rmd$"
,
"md"
,
basename
(
src_rmd
)))
for
(
i
in
seq_along
(
src_rmd
))
{
knitr
::
knit
(
src_rmd
[
i
],
output
=
dest_md
[
i
])
}
This diff is collapsed.
Click to expand it.
bin/knit_lessons.sh
0 → 100755
+
5
−
0
View file @
6bb7b27a
#!/usr/bin/env bash
if
[
-d
"_episodes_rmd"
]
;
then
Rscript
-e
"source('bin/generate_md_episodes.R')"
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment