Повторение строки

Простые типы / Строки

str_v <- strrep("7", 3)
# str_v = 777

# Any string repeats, not only one char
laugh <- strrep("ha", 3)
# laugh = hahaha

# Zero count: empty string
empty <- strrep("7", 0)
# empty =

# A vector of counts: one result for each
stairs <- strrep("ab", 1:3)
# stairs = ab abab ababab

cat("str_v =", str_v, "\n")
cat("laugh =", laugh, "\n")
cat("empty =", empty, "\n")
cat("stairs =", stairs, "\n")

# A negative count is an error
neg_error <- tryCatch(strrep("7", -1),
                      error = conditionMessage)
cat("neg_error =", neg_error, "\n")
# neg_error = invalid 'times' value