Library contents

R strrep

Repeat a short display token to build a three-place progress indicator.

A simple example

strrep

  1. Start with "a", count 3
  2. Do this Repeat the text
  3. Result "aaa"
Three copies are placed next to one another.
Lesson.R
value <- "a"
cat(strrep(value, 3), "\n", sep = "")
Output
aaa

Syntax

R syntax
strrep(value, 3)
Run these examples in R

Save one example at a time as Lesson.R. Use R 4.x.

Rscript --vanilla Lesson.R

Draw three completed checkpoints

A progress display shows one mark for each completed checkpoint. Generate the three marks from the completion count so the same code can display another count later.

From the programvalue <- "+"
Result+++
Lesson.R
value <- "+"
cat(strrep(value, 3), "\n", sep = "")
Output
+++

Each plus sign stands for one completed step.

Advertisements

Mark three empty seats

A small text-only display uses a repeated mark to represent a divider or a count. Generate the marks from the requested number so the visual result grows or shrinks with the input.

From the programvalue <- "[]"
Result[][][]
Lesson.R
value <- "[]"
cat(strrep(value, 3), "\n", sep = "")
Output
[][][]

The whole two-character token is repeated three times.

Mark a workshop attendance card

A student attends three workshop sessions. The card printer repeats one mark for every earned stamp. What strip appears on the card?

Given3 sessions · mark *
Worked result***

What to watch for

Set a sensible upper bound before repeating text according to user input.

Documentation for strrep