I try to do a blog using the trio jekyll, rmarkdown and github (as here: http://yihui.name/knitr-jekyll/)
I have all my .Rmd in _source, and I have this issue that sometimes the plots are knit in base 64 images and sometimes saved in a figure folder.
First question, why?
Second question: when my plot are saved as images, the path in the html appear to be figure/source/. Knowing that the destination folder is /blog/ (my baseurl in _config.yml), to make it work, it should be blog/figure/source.
Strangely, they are displayed locally and when I open the html with my browser. But when I deploy my website on github, the images aren't displayed, as the path is incorrect.
How to define the path to /blog/figure instead of /figure/ ?
Edit: the link to my blog, still in development: http://yvescr.github.io/
But the Rmd don't appear in the github account, as the folder I synchronised with github is the destination file of the jekyll generation.
_config.yml:
# Build settings
markdown: kramdown
baseurl: "/blog"
In R:
jekyll(dir = ".", input = "_source", output = "_posts", script = c("Makefile", "build.R")
, command = "jekyll build --destination ../blog")
build.r:
local({
# fall back on '/' if baseurl is not specified
baseurl = servr:::jekyll_config('.', 'baseurl', '/')
knitr::opts_knit$set(base.url = baseurl)
# fall back on 'kramdown' if markdown engine is not specified
markdown = servr:::jekyll_config('.', 'markdown', 'kramdown')
# see if we need to use the Jekyll render in knitr
if (markdown == 'kramdown') {
knitr::render_jekyll()
} else knitr::render_markdown()
# input/output filenames are passed as two additional arguments to Rscript
a = commandArgs(TRUE)
d = gsub('^_|[.][a-zA-Z]+$', '', a[1])
knitr::opts_chunk$set(
fig.path = sprintf('blog/figure/%s/', d),
cache.path = sprintf('cache/%s/', d)
)
knitr::opts_knit$set(width = 70)
knitr::knit(a[1], a[2], quiet = TRUE, encoding = 'UTF-8', envir = .GlobalEnv)
})
makefile:
all:
Rscript -e "servr::jekyll('..')"
clean:
rm -r ../blog/
I solve my issue, I post it here in case people have the same:
The jekyll() function in R compile the .rmd (in _source) in .md(in _post) with knitr(I think) then call the jekyll command.
Here, my issue was that when I changed the _config.yml file, with modification of the path, the .md are not re-created and so the path is not changed.
To make it work, I had to delete manually the .md in _source then re-run the jekyll() function.
Concerning the images, they are compiled as 64 images when I use rmarkdown without cache.
With the cache, knitr create images in a folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With