From 793d6dc58d953ce969ea9724e268995a539db4ea Mon Sep 17 00:00:00 2001 From: HannesOberreiter Date: Tue, 11 May 2021 08:18:36 +0200 Subject: [PATCH] Update 08_Conditions.Rmd Spliced the example `7.1 Signalling conditions Q2` into two distinct functions one for `message` and one for `cat`. For me it makes it cleaner and easier to understand. "I assign the copyright of this contribution to Malte Grosser and Henning Bumann". --- 08_Conditions.Rmd | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/08_Conditions.Rmd b/08_Conditions.Rmd index 95dfe8c8..054c42a9 100755 --- a/08_Conditions.Rmd +++ b/08_Conditions.Rmd @@ -47,19 +47,29 @@ __[A]{.solved}__: The `appendLF` argument automatically appends a new line to th multiline_msg <- function(appendLF = TRUE) { message("first", appendLF = appendLF) message("second", appendLF = appendLF) - cat("third") - cat("fourth") } multiline_msg(appendLF = TRUE) #> first #> second -#> thirdfourth multiline_msg(appendLF = FALSE) -#> firstsecondthirdfourth +#> firstsecond ``` -Comparable behaviour regarding line breaks for `cat()` can be achieved via setting its `sep` argument to `"\n"`. +Comparable behaviour regarding line breaks for `cat()` can be achieved via setting its `sep` argument to `"\n"`: + +```{r, eval=FALSE} +multiline_cat <- function(sep = "\n") { + cat("first", sep = sep) + cat("second", sep = sep) +} + +multiline_cat(sep = "\n") +#> first +#> second +multiline_cat(sep = "") +#> firstsecond +``` \stepcounter{section} ## Handling conditions