[R] Need to have more control on cat()

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Sep 13 13:00:36 CEST 2010


On Mon, Sep 13, 2010 at 11:53 AM, Christofer Bogaso
<bogaso.christofer at gmail.com> wrote:
> Hi all, here is my small piece of codes:
>
> fn1 <- function(x = 4) {
>    y <- 0
>    if(y == 0) cat("y value
>                    is zero\n") # I intentionally created 2nd line here
>    return(4)
> }
>
> If I run this function I get following
>
>> fn1()
> y value
>                    is zero
> [1] 4
>
> Here you see there are lot of spaces before "is zero". How can I
> format cat() to force it to start from margin?

 Don't indent it? This isn't Python, you know.

  if(y==0){cat("y value
is zero\n")
    }

 should work, producing

y value
is zero

 is that what you want?

Barry



More information about the R-help mailing list