OMA icon indicating copy to clipboard operation
OMA copied to clipboard

Add solutions to training exercises as foldable code chunks

Open RiboRings opened this issue 1 year ago • 16 comments

The Exercise chapter has plenty of exercises. Let's add solutions to them as foldable code chunks, closed by default and opened when user clicks on them.

It can be done with:

output:
  html_document:
    code_folding: hide

RiboRings avatar Jul 03 '23 09:07 RiboRings

When there is time we have received regular requests to add solutions for the exercises.. would be nice to see some community contributions here.. :-)

antagomir avatar Jul 18 '23 21:07 antagomir

Link and text of pr https://github.com/microbiome/OMA/pull/390

Hi! Before switching to BiocBook we were considering to add foldable solutions to the exercises. Here I added solution chunks to a couple of exercises so if anyone is willing to expand they can use the blueprint used in this PR. For example:

#| label: exercise-name-chunk1
#| eval: FALSE
#| code-fold: true
#| code-summary: "Show solution"

# Write solution here

Ideally, break down solution chunks into steps same way as the exercises are fragmented.

RiboRings avatar Feb 09 '24 14:02 RiboRings

Giulio - could you check if this is easy to add in the new version of the book?

antagomir avatar Apr 10 '24 20:04 antagomir

If not easy then let's rethink.

antagomir avatar Apr 10 '24 20:04 antagomir

Hi! In theory, this should be working in the current version of the book. However, the folded code doesn't appear in the chapter. Not sure yet what the problem is.

RiboRings avatar Apr 16 '24 07:04 RiboRings

The reason could be that code folding is only supported by executed code chunks: https://quarto.org/docs/output-formats/html-code.html

Maybe we could run the code in the examples, or if that takes too long we could comment out all the lines of the example chunks and "execute" it.

RiboRings avatar Apr 16 '24 10:04 RiboRings

hmm perhaps we could first add this to some light-weight cases where it is simple; for more heavy examples there could be a link to an external file (in OMA repo but not included in the book)?

antagomir avatar Apr 16 '24 14:04 antagomir

For some reason, the folded chunks appear locally, but they are not rendered in the online version of the book. Below is a picture of what is looks like when rendered locally:

Screenshot 2024-04-17 at 10 52 02

RiboRings avatar Apr 17 '24 07:04 RiboRings

Some possible actions:

  • test if chunk appears in the online book when setting EVAL = TRUE (also precede all lines with # so they don't execute
  • understand why code folding works only locally, and try to fix it in the online book

RiboRings avatar Apr 17 '24 07:04 RiboRings

@RiboRings solution works fine. We can check it here (https://ake123.github.io/OMA/docs/devel/pages/98_exercises.html#sample-information)

ake123 avatar Apr 17 '24 13:04 ake123

Thank you @ake123

Then in principle if someone is willing, they can add solutions to selected exercises in preparation for summer schools and courses as shown in the comment above.

RiboRings avatar Apr 18 '24 14:04 RiboRings

I am willing to add solutions. I can actually do all if needed

ake123 avatar Apr 18 '24 15:04 ake123

That would be super useful!

@antagomir mentioned that we might need to consider whether it makes sense to add solutions to all exercises, or if it is only necessary for the more complex exercises, and the easier exercises would just contain a link to the corresponding OMA chapter (also to avoid redundant code).

How should we proceed?

RiboRings avatar Apr 18 '24 18:04 RiboRings

I could review the exercises and see which ones would benefit from solutions. This will take some time. But next week we run a training events, this can bring some clarity.

antagomir avatar Apr 19 '24 12:04 antagomir

Ok @ake123 if you could do the following for the material in chapter 18.3? https://microbiome.github.io/OMA/docs/devel/pages/98_exercises.html

  1. Go through those exercises, and verify that they are clear and work well. Improve the exercise text or tips where necessary.

  2. Add citation to the relevant OMA chapters / function names as a tip; also the tips can be folded

  3. provide brief (folded) example solutions for those exercises where it seems useful; if the solution is obvious from the material that is already provided in the proper chapters, then see if it is enough to just cite the relevant chapter. We don't want to duplicate all material from the book to the exercises as this doesn't make sense.

  4. Where possible, avoid referring to specific data sets in the exercise text; the solution needs to operate on concrete data however.

Let's see how this works for chapter 18.3, then we can see how to do with the other chapters.

antagomir avatar Apr 22 '24 15:04 antagomir

Solutions are ready!

ake123 avatar Apr 26 '24 10:04 ake123

@jkc9886 could you check if the exercise chapter contains tasks for which you could propose solutions (as a PR)?

antagomir avatar Jul 22 '24 13:07 antagomir

Foldable chunks seems to work now. It seems we can close this.

antagomir avatar Jul 23 '24 20:07 antagomir