I would like to format output of a print statement so that elements in the print statement are separated by a small uniform gap, a gap of either 1, 3 or 5 empty spaces. Is that possible?
In the example below, I think all of the elements in the print statement are assumed to be
as long as the first element in the print statement (here either as long as aa1
or aa2
).
The print.gap
statement does not result in the desired format. It simply adds an
additional constant number of spaces between each element.
aa1 <- 'abcdefghijklmnopqrstuvwxyz'
aa2 <- 'abc'
bb <- 10
cc <- 222
print(c(aa1,bb,cc))
# [1] "abcdefghijklmnopqrstuvwxyz" "10" "222"
print(c(aa2,bb,cc))
# [1] "abc" "10" "222"
# desired output:
# [1] "abcdefghijklmnopqrstuvwxyz" "10" "222"
#
# or
#
# [1] "abcdefghijklmnopqrstuvwxyz" 10 222
Thank you for any advice. Perhaps I must use a cat
statement and sprintf
instead of a print
statement. Maybe some variation of this: How to print R variables in middle of String