Search code examples
rr-markdowntravis-cibookdown

path to images in bookdown build through travis


I have a repository with a series of Rmd files that are build using Bookdown. Within those Rmd files, there is a call to images that are within a folder (also within the repository). If I open each Rmd file from the master branch the images are rendered correctly. However, I tried to build the book and push the built-book to a gh-pages branch (which also contains the images folder) using Travis and use Github pages but the images didn't render. The built book is here.

To call the images within the Rmd files I use lines like this:

![**Fig. 0** Terminal en RStudio](./docs/non-plain/img/rstudio_terminal.png)

If I inspect the broken image in the built book the path contains locals folders of my computer, which I don't really understand given that all paths within the Rmd files are relative. I also tried to call the images using this (within an R code chunk) but it didn't work either:

knitr::include_graphics("/docs/non-plain/img/config_git.png")

I'm using a .travis.yml, taken from the Bookdown manual, that call a _build.sh and a _deploy.sh script.

.travis.yml

language: r
cache: packages
pandoc_version: 1.19.2.1

before_script:
  - chmod +x ./_build.sh
  - chmod +x ./_deploy.sh

script:
  - ./_build.sh
  - ./_deploy.sh

_build.sh

#!/bin/sh

Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')"

_deploy.sh

#!/bin/sh

set -e

[ -z "${GITHUB_PAT}" ] && exit 0
[ "${TRAVIS_BRANCH}" != "master" ] && exit 0

git config --global user.email "email.com"
git config --global user.name "username"

git clone -b gh-pages https://${GITHUB_PAT}@github.com/${TRAVIS_REPO_SLUG}.git book-output
cd book-output
cp -r ../_book/* ./
git add --all *
git commit -m"Update the book" || true
git push -q origin gh-pages

I can't grasp what I'm doing wrong and why images are not being rendered properly. Any help is appreciated.


Solution

  • A workaround would be to use the url of the image on github as a path.

    I have a similar problem using bookdown::render_book(), I think it is because images path is relative to the chapter .Rmd files, which are in a folder different from the index.Rmd