I would like to ask if there is a way to align text after we have entered it in gtext.
For example
x <- c(123.4, 5.6)
y <- c(1.2, 3.657)
z <- c(12345.6, 789.4)
df <- data.frame(x, y, z)
df.co <- capture.output(df) # get df as text
for (i in 1:length(df.co))
{
str.split <- strsplit(df.co, "\\s+") # split every line in its components
}
w3 <- gwindow()
gt3 <- gtext(container=w3)
for (i in 1:length(str.split)) # length(str.split)=3
{
for (j in 1:length(str.split[[i]])) # length(str.split[[i]])=2
{
str.split[[i]][[j]] <- paste(str.split[[i]][[j]],"\t",sep="",collapse="") # add tab to each component
}
str.split[[i]] <- paste(str.split[[i]], sep="", collapse="") # join to one line
insert(gt3, str.split[[i]])
}
This way we mimic the R console.
Thank you a lot, in advance
There is no way to align text in the sense of right-align/centre/etc in gWidgets.
I recommend monospace fonts as @Dason suggested (although that seems to be the default for me).
In terms of your code, you can clean it up a little:
iand you are writing overstr.spliteach time)str.split[[i]]str.splitin separately, you can do it all at once.In summary:
Alternately, you can replace everything after
df.co <- capture.output(df)by:(do the two side-by-side and compare:
insert(gt3,df.co)right-aligns each column of the dataframe, exactly as typingdfwould show; the method you have (insert(gt3,str.joined)) left-aligns each column.