2

I am writing a swirl lesson using swirlify package functions in RStudio.
Below is how lesson.yaml file looks like now

- Class: text
  Output: Welcome to Part 1 Playing with Numbers!!!

Output for which looks like

enter image description here

How to insert a new line or line break after Welcome to Part 1 in lesson.yaml file above, so that it displays the output as below when I run the demo_lesson() command again after saving the lesson.yaml file

| Welcome to Part 1

| Playing with Numbers!!!

www
  • 38,575
  • 12
  • 48
  • 84
Sowmya S. Manian
  • 3,723
  • 3
  • 18
  • 30

2 Answers2

3

Using YAML, you can use any of these equivalent approaches:

  • Quoted string with escape
- Class: text
  Output: "Welcome to Part 1\nPlaying with Numbers!!!"
  • Literal scalar
- Class: text
  Output: |-
    Welcome to Part 1
    Playing with Numbers!!!

(| starts a literal scalar and - tells YAML to drop the final line break.)

  • Multiline scalar
- Class: text
  Output:
    Welcome to Part 1

    Playing with Numbers!!!

(since one line break gets folded into a space, you need two line breaks.)

Since I do not know whether swirlify nicely handles line breaks in the string, I guess you could also do

- Class: text
  Output: Welcome to Part 1
- Class: text
  Output: Playing with Numbers!!!
flyx
  • 35,506
  • 7
  • 89
  • 126
  • I am working on Windows 10, and I tried `|-, |+, >, >+` everything on RStudio, its not working for me. I know the last solution to put it in two different class sections, but I have all the contents in kind of heading and then a paragraph, so heading should be separated somehow from paragraph in the output. – Sowmya S. Manian Dec 09 '16 at 10:40
  • How is it not working? What's happening when you do it? – flyx Dec 09 '16 at 13:36
  • I'll post my output. – Sowmya S. Manian Dec 10 '16 at 10:21
  • Its working when I hit enter twice in the `lesson.yaml`, Thanks could you please edit your second block of code in your answer, just one more enter. Then its working with the literal `|-` Thanks a lot!!! – Sowmya S. Manian Dec 10 '16 at 15:45
  • Same way it works with double `\n\n` for quoted string with escape, 1st block of answer – Sowmya S. Manian Dec 10 '16 at 15:56
  • For block three without literal `|-`, it works with three times Enter and the 4th Block is already working because of two different class Sections!!! – Sowmya S. Manian Dec 10 '16 at 16:04
  • Hey Accepted your answer, do let me know because all your answers are working with either one extra new line or extra enter.. dont know why but its working.. – Sowmya S. Manian Dec 10 '16 at 16:43
  • It seems like something is line-folding your input twice. This is either a bug in the YAML implementation or something else in the `swirlify` toolchain. I don't know any of it, so I cannot point my finger to it. – flyx Dec 10 '16 at 20:09
0

Thanks to flyx for answering the question, here is how it works!!

I. Quotes string with escape (Works with two \n\n)

lesson.yaml file

enter image description here

II. Literals

First line in Output: |- Hit ENter once Indent once by pressing one Tab for first line, Hit Enter twice to have break between header line and paragraph like below, then it works..

lesson.yaml file

enter image description here

III. Mulitline Scalar (Works with three times Enter between two lines)

Press Enter once After Output: in lesson.yaml Indent once by pressingTab` key once, Write your first line, hit Enter thrice and write the second line. Then it works.

lesson.yaml file

enter image description here

OUTPUT FOR ALL THE ABOVE ANSWERS

enter image description here

Sowmya S. Manian
  • 3,723
  • 3
  • 18
  • 30