0

Let's say I have the following vector:

output <- c("foo\n", "bar\n")

If I want to display this via cat, I get a weird indentation:

> cat(output)
foo
 bar

Why is there a space before "bar"? I can get around it with paste:

> cat(paste(output, collapse = ""))
foo
bar

but I don't understand why cat is behaving in this fashion in the first place? Is this a bug, or am I missing something about how cat behaves?

1 Answer 1

3

cat has a sep argument.

From ?cat:

sep: a character vector of strings to append after each element.

sep defaults to " ".

Hence:

output = c("foo\n", "bar\n")
cat(output, sep = "")
foo
bar

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.