Bookdown contest submission: mindr: convert a bookdown project into a mind map, and vice versa

mindr is an R package I developed originally from using bookdown: what if a book is presented as a mind map, or what if writing a book out of a mind map?

For example, throw the .Rmd files of the book bookdown: Authoring Books and Technical Documents with R Markdown into a folder 'bdb' in your working directory, and run:

mindr::markmap(folder = 'bdb', remove_curly_bracket = T)

then a mind map will be generated and displayed in your viewer, showing a tree structure of the book.

You could click the nodes to extend or collapse them. Different themes are available.

mindr can generate mind maps for third-party software as well. Let's throw the .Rmd files of the book blogdown: Creating Websites with R Markdown into a folder 'bld' in your working directory, and run:

mindr::md2mm(folder = 'bld')

you will get a file mindr.mm, which could be opened with any mind-map (brainstorm) software such as the desktop software 'FreeMind' and 'XMind', or the online webware 'mindmeister'.

In the figure you can see the attributes after section headers, which can be removed by using the parameter remove_curly_bracket = TRUE.

With Xmind, you can use a theme you love the best. Here is a mindmap from Bookdown contest submission: Master Thesis Template from China University of Mining and Technology, Beijing in Xmind:

and the book Learning R: R for Rookies:

The examples above showed only a half of mindr. You could first draw the outline of a book in a mindmap in Xmind or Freemind, save it as an .mm file, and then use the function mindr::mm2md() to convert it into a markdown file, and then go on with the contents of the book. The details can be found in the mindr repo .

Have fun with bookdown and mindr!

3 Likes

This is a very creative package! Thanks for sharing!

There are a couple of minor details that I think could be improved:

  1. The attributes after section headers can be removed, such as {-} after Yihui Xie in the mind map for the blogdown book (the second image above).
  2. To identify section headers robustly, you may try to convert Markdown to JSON via Pandoc, instead of using regular expressions. In your first image, a literal code chunk is not a section header but a comment.
  3. You'll have to adjust the levels of headers for parts and appendices, e.g., when you find # (APPENDIX), it is probably a better idea to show all the rest of first-level headers as second-level headers (and Appendix is the first-level header).

Thanks a lot for the suggestions! They are very useful to improve mindr. My replies are as follows.

  1. Yes, the attributes after section headers can be removed by using the parameter remove_curly_bracket = TRUE:
mindr::md2mm(folder = 'bld', remove_curly_bracket = TRUE)

This will be added into the post.

  1. You are definitely correct. Comments are taken care of in mindr, but apparently I missed something. I will double check it. Converting Markdown to JSON is something new to me and I will keep an eye on it.

  2. I totally agree. # (PART) and # (APPENDIX) are quite 'bookdownish', which the current version of mindr is missing...

The newest version of mindr has solved these problems. A parameter 'bookdown_style' was added to the function md2mm. If the user choose the bookdown style, then mindr will

  1. put 'index.Rmd' before all the rest files, and
  2. lower the levels of the chapter headings if there is # (Part), # (APPENDIX) or # Reference.

A new mind map for the blogdown book has been produced from all the .Rmd files of the blogdown repo:

In the case of the mismatched section headers, the new mindr firstly excludes the code blocks surrounded by a pair of four backticks, then excludes the code blocks surrounded by a pair of three backticks. Normally it gives a satisfactory mind map. However, the bookdown book somehow has a non-paired backticks in chapter 6, which begins with three backticks, and ends with four. This makes mindr lose his mind. If one backtick is removed, then the mind map is just fine.

Still not sure how to do the json stuff.

1 Like